conda common command summary, query at any time (the most complete)

Conda is an open source software package management system and environment management system, which is used to install multiple versions of software packages and their dependencies, and easily switch between them.

Under Windows, Anaconda Prompt needs to be installed and used; Under Linux, you can directly execute the conda command.

  1. Create a new environment

conda create -n your_env_name python=X.X 
# or
conda create --name your_env_name python=X.X

-n is -- name, your_env_name is the name of your customized environment.

For example:

​conda create -n newenv python=3.7
# python=3.7 installs the latest version of the python 3.7 series (such as 3.7.12)
# To specify a more detailed version, use python=3.7.2

2. Activate an environment

activate. That is, entering an environment.

Windows system:

activate your_env_name

Linux system:

source activate your_env_name

After activating the environment, you can check the Python version in the current environment:

python --version

3. Installation and deletion of package and deletion of environment

After activation to the specified environment, you can directly install the required packages into the environment:

Installation package:

conda install [package] 
# For example: conda install numpy
# Specify the package version: conda install xlrd=1.2.0 (note the single equals sign)
# You can also use pip install to install pip install xlrd==1.2.0 (note the double equals sign)
# View available versions: pip install spyder==*

Delete a package in the current environment:

conda remove [package] 
# Please note: not conda uninstall
# pip uninstall is only available under the pip instruction

Upgrade a package:

conda update [package]
# conda update --all upgrade all packages

Exit the current virtual environment:

source deactivate  # Linux environment

deactivate # Windows Environment

Delete a virtual environment:

conda remove -n your_env_name --all
# -n is -- name

Copy a virtual environment:

conda create --name new_env_name --clone old_env_name 

When confirming [Y/N] before installation, false means that the user will make a decision instead of directly:  

conda config --set always_yes false

4. Environment query

To see which packages are installed:

conda list

View what virtual environments are currently available:

conda env list
# or
conda info --envs

Query environment python version:

python --version

Query conda version:

conda --version

Update conda:

conda update conda

View conda environment details:

conda info

5. Sharing / backup environment

A quick way to share your environment is to give him a. yml file of your environment.

First activate the environment to be shared and generate an environment.yml file in the current working directory.

conda env export > environment.yml

After the other party gets the environment.yml file, put the file in the working directory, and you can create an environment from the file through the following command.

conda env create -f environment.yml

6. Mirror source

conda method:

  View mirror source:

conda config --show channels

Add image source (such as Qinghuayuan):

conda config --add channels
conda config --add channels
conda config --set show_channel_urls yes

# conda config --set show_channel_urls yes means to display the url of the channel when installing the package from the channel, so that you can know the installation source of the package.

Clear the index cache to ensure that the index provided by the mirror station is used:  

conda clean -i

Search package:  

conda search [package]

Switch back to the default source:

conda config --remove-key channels

Remove a mirror source (such as Qinghua source):

conda config --remove channels

pip method:

Temporarily specify the image source used to install a package:

pip install [package] -i
pip install [package] -i --trusted-host

Tsinghua University:
 Alibaba cloud:
China University of science and technology
Huazhong University of Technology:
Shandong University of Technology: 

7. Cleaning

Delete unused packages:

conda clean -p     

Delete tar package:

conda clean -t     

Delete all installation packages and cache s:

conda clean -y --all 

Tags: Python Windows Machine Learning

Posted on Wed, 24 Nov 2021 08:22:04 -0500 by budz