Concise Guide conda

区分 conda, loved, the niconda

anaconda equivalent conda + python + pip + python pile common in scientific computing package (numpy, scipy, matplotlib etc.)

miniconda equivalent conda + python + pip, lightweight.

conda is generic package manager, pip package can be installed (e.g. numpy), the package can also be installed in other languages ​​(e.g. ninja, cmake).

If you use Python, so the depth of learning, it is strongly recommended that you use miniconda / anaconda rather than the system comes with Python / PIP , although may consume more disk space, but often can save time overhead on the environment configuration.

conda version

conda -V

or

conda --version

Virtual Environment

Create a virtual environment

conda create -n env_name python=x.y

eg python3.5 create a virtual environment:

conda create -n py35 python=3.5

To delete a virtual environment

conda remove --name env_name --all

Rename the virtual environment
can not directly rename a virtual environment, only a very naive from the legacy environment clone, and then delete the original environment (or use the following "shared environment" approach, but the estimated need for networking slower):

conda create --name new_name --clone old_name
conda remove --name old_name --all

Lists the virtual environment

conda env list

or:

conda info --envs
#也可以用缩写形式:
conda info -e

Switching / activating virtual environment

conda activate env_name

eg activation py35 environment:

conda activate py35

Exit current virtual environment

conda deactivate

Share Environment

Export virtual environment
exported to yml file, equivalent to pip with an upgraded version of requirements.txt

conda env export > environment.yml

Yml created using the Import virtual environment

conda env create -f environment.yml

Copy the virtual environment

conda create -n new_env_name --clone env_name

Check the location of an environment

The default conda virtual environment called the "base", python it provided /home/zz/soft/miniconda.

virtual environment outside the base environment, for example py35, in /home/zz/soft/miniconda3/envs/py35/.

In some open source projects compiled configuration environment (eg OpenCV, etc.), you can specify a particular version of python, you need to go to /home/zz/soft/miniconda3/envs/py35/this location to find.

Package list

Basic information packet
display basic information about all packages in the current environment

conda list

Displays basic information about all packages specified virtual environment

conda list -n env_name

Conda distinguishing information display packages and pip
current environment:

conda env export

The output of the - pipstart lists pip package list.

conda env export -n env_name

Installation package

In the current virtual environment installation package

conda install pkg_name

eg install cmake (cmake is not a pypi package, but can be conda download and install, and if you configure the mirroring condarc in domestic, download it will be very fast, much faster than their official website to download a manual to cmake):

conda install cmake

In the specified virtual environment installation package

conda install --name env_name pkg_name

From the specified channel to download and install
to download the package pytorch Example:

conda install --channel https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/ pytorch

Abbreviations or parameters -cAlternatively --channels, with ~/.condarcthe configuration of the channel named pytorch

conda install -c pytorch pytorch

Removing Packages

The current environment

conda remove pkg_name

Specifies the environment

conda remove --name env_name pkg_name

Find Package

conda search pkg_name

conda Configuration

.condarc
Linux/Mac: ~/.condarc
Windows: c:/Users/xxx/.condarc

Domestic use tuna in conda mirror . This individual felt that the various .condarc Channel configuration, on the one hand are different versions of the management packet (e.g. pytorch this Channe), on the other hand can be switched mirror, to accelerate.

channels:
  - defaults
show_channel_urls: true
default_channels:
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r
custom_channels:
  conda-forge: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  msys2: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  bioconda: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  menpo: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  pytorch: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  simpleitk: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud

pip.conf
Linux/Mac: ~/.pip/pip.conf
Windows: C:/Users/xxx/pip/pip.ini

In addition to configuring conda mirror, the mirror needs to be configured pip. Because many packages still need to pip python instead conda installation (conda there are no corresponding packet, only pypi there), then use pip to accelerate domestic mirroring needs to be configured pip.conf, for example:

[global]
index-url = https://mirrors.aliyun.com/pypi/simple/

[install]
trusted-host=mirrors.aliyun.com

bash / zsh automatically load
previously been installed miniconda / anaconda When you select "yes", it is automatically added to the configuration ~/.bashrc, and then manually copied to ~/.zshrc(I use zsh instead of the default bash as interpreter). In fact, more simply:

conda init zsh

Enter bash / zsh does not automatically activate base env

conda config --set auto_activate_base false

Guess you like

Origin www.cnblogs.com/zjutzz/p/11871266.html