current position:Home>Explain Python CONDA in detail

Explain Python CONDA in detail

2022-05-15 04:27:25The way of Python data

source :pythonic Biological man

This article continues to introduce Anaconda Of Strong housekeeper Conda: can Flexible management python My bag package And the environment environment.

Conda brief introduction

  • Packages for multiple programming languages package And virtual environments environment Management of ;

  • Very simple to complete package Installation 、 function 、 to update 、 Delete 、 Dependence problem ;

  • operational repo.anaconda.com On 7,500+ packages ;

  • Very simple to complete the construction of different environments 、 preservation 、 Loading and switching ;

  • Support language 【 This article only introduces python operation 】:Python、R、Ruby、Lua、Scala、Java、JavaScript、C / C ++、FORTRAN;

  • Support operating system :Windows, macOS and Linux.

Contents of this article

1、 Download source channel Detailed explanation 
 The domestic part is easy to use conda Download source 
  Tsinghua University source 
  University of science and technology of China 
  The domestic part is easy to use pip Download source 
pip Source usage 
  To configure conda Download source 
  Method 1 
  Method 2 
 View the configured download source 
 View the configured download source priority 
 Delete download source 
  Method 1 
  Method 2 

2、conda System related commands 
 Query a conda Command help documentation 【 The most useful command 】
 see conda System version and other information 
 see conda All configuration information 
conda Version update 
Anaconda Update all packages in 
conda to update python

3、 package package management 
 see 【 The current environment 】 All packages installed 
 see 【 The current environment 】 already installed 【 Specified package 】 Information 
 see 【 Specify the environment 】 Installed package information 
 View the available versions of the package 
 View a range of version packages 
 Install the latest version of package 
 Specify the version pack installation 
 Appoint list Medium version package installation 
 Install the package in the specified range 
 Package installation skipped 【y/n】
 Install the package into the specified environment 
 Current environment package update 
 Specify the environment package update 
 Package uninstall 

4、 Environmental Science environment management 
 View the existing environment 
 Create an environment 
 Environment activation 
 Environment exit 
 Environmental cloning 
 Environment delete 

5、Conda、pip And virtualenv Three more 

1、 Download source channel Detailed explanation

Download source , That is, the website where you download things ;
because Anaconda Our server is abroad , The default source is Anaconda.org, Downloading corresponding resources in China is slow , Therefore, it is necessary to set up domestic Anaconda Mirror source .

The domestic part is easy to use conda Download source

  • Tsinghua University source

website :https://mirror.tuna.tsinghua.edu.cn/help/anaconda/

# Tsinghua University source 
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/cloud/conda-forge/
https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/
  • University of science and technology of China

website :https://mirrors.ustc.edu.cn/

# University of science and technology of China 
https://mirrors.ustc.edu.cn/anaconda/pkgs/main/
https://mirrors.ustc.edu.cn/anaconda/pkgs/free/
https://mirrors.ustc.edu.cn/anaconda/cloud/conda-forge/

The domestic part is easy to use pip Download source

# Tsinghua University source 
https://pypi.tuna.tsinghua.edu.cn/simple

# China University of science and technology 
https://pypi.mirrors.ustc.edu.cn/simple/

# Douban source 
https://pypi.doubanio.com/simple
  • pip Source usage

pip install pandas -i https://pypi.tuna.tsinghua.edu.cn/simple# Download using Tsinghua source pandas package 

To configure conda Download source

  • Method 1

Take the configuration of Tsinghua University source as an example .

conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
conda config --set show_channel_urls yes

conda config --set show_channel_urls yes The function of is to display the installation source of the package , as follows
8f04fdfe11c914503e740fdec814dd8c.png

  • Method 2

linux Open down /home/xx/.condarc file , Add the following content and save it

channels:
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
  - defaults
show_channel_urls: true

windows Default to none .condarc file , need conda config --set show_channel_urls yes Mr Into , Then add the above content .

View the configured download source

conda config --show channels
d818ae11261b3419b21dd52c927b3b0b.png

View the configured download source priority

conda config --get channels

The default source priority has been reduced to the lowest , The newly added Tsinghua source has the highest priority 555d910fb093f62a492c616e06c6b8dd.png

Delete download source

  • Method 1

Delete directly .condarc file

  • Method 2

conda config --remove channels channels_Name

conda config --remove channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --remove channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/

2、conda System related commands

Query a conda Command help documentation 【 The most useful command 】

conda config -h
c9e3a935e965abfd2e4686714e61a115.png

see conda System version and other information

conda info
929424f30accb4bad39b529d57371b6d.png

see conda All configuration information

conda config --show

The following sections are listed a7d77974a397b8a416f68d30f023e1cd.png

conda Version update

take conda Update to the latest version

conda update -n base conda

Anaconda Update all packages in

conda update anaconda

conda to update python

to update python To the latest version of the current series , At present, it is python2, Can only be updated to python2 The highest version in , Instead of updating to python3.

conda update python

3、 package package management

see 【 The current environment 】 All packages installed

conda list

Output four columns ,Name( Package name )、Version( Package version number )、Build( Package Creator )、Channel( Package download source ).b87602d9212c8ece8435f424de098376.png

see 【 The current environment 】 already installed 【 Specified package 】 Information

conda list PACKAGE_NAME
87dfb1d7a1e13e1d88f24647b746c142.png

see 【 Specify the environment 】 Installed package information

conda list -n ENV_NAME

conda list -n python2.7# Look at the environment python2.7 All packages installed under 

View the available versions of the package

conda search PACKAGE_NAME

conda search pandas# With pandas For example 
d9e87c1c1b494fae26ceb9ffb5109acf.png

View a range of version packages

conda search "PKGNAME [version='>=1.0.0,<1.1']"

conda search "pandas [version='>=1.0.0,<1.1']"# The search version is in 1.0.0 And 1.1 Between pandas

Install the latest version of package

conda install PACKAGE_NAME It is installed in the currently active environment by default , Install the latest version

conda install pandas# Install the latest version by default 

Specify the version pack installation

conda install PACKAGE_NAME=VETSION_CODE

conda install pandas=1.1.1# install 1.1.1 Version of pandas

Appoint list Medium version package installation

conda install "PACKAGE_NAME[version='1.0.4 |1.1.1']"

conda install "pandas[version='1.0.4 |1.1.1']"# install pandas 1.0.4 Version or 1.1.1 edition 

Install the package in the specified range

conda install "PACKAGE_NAME>1.0.4,<1.1.1"

conda install "pandas>1.0.4,<1.1.1"# The installed version is in 1.0.4 To 1.1.1 Between pandas

Package installation skipped 【y/n】

conda config --set always_yes yes
By default conda config --set always_yes false, In other words, the installation process will ask whether to continue the installation , Set to yes No more pop-up requests .c227ef4d628ad749ec1532e527a976f6.png Install the package into the specified environment

conda install -n ENV_NAME PACKAGE_NAME

You can do this , But it's not necessary at all , It is recommended to activate the environment to be installed first , And then install it

conda install -n python2.7 pandas# take pandas Installed in the environment python2.7 in 

Current environment package update

conda update PACKAGE_NAME

conda update pandas

Specify the environment package update

conda update -n ENV_NAME PACKAGE_NAME

Package uninstall

conda remove/uninstall PACKAGE_NAMEremove and uninstall Fine

conda remove pandas

4、 Environmental Science environment management

View the existing environment

The following three methods can .

conda info -e
conda info --envs
conda env list
66767fe34bdc7a66f8a407950a493f47.png

Create an environment

conda create --name ENVNAME python=3.6

conda create -y -n python2.7 python=2.7.7

-y#-y, --yes  Do not ask for confirmation. That is, the installation process does not need to enter y confirm
-n  python2.7# Set the environment name to python2.7
python=2.7.7# The version of the environment is python=2.7.7, It can be done by conda search python Retrieve the installable version number
The following indicates that it has been created successfully .20f5109ca7b8e4b0330d387f8a93a94b.pngconda info -e View all current conda Create an environment

cab3366efe187dfe2315284522ddf9a8.png

Environment activation

conda activate python2.7

At this point, the environment becomes Python2.7f97f0cb3b26f2ec61d00aa851299bcb5.png

  • Be careful 1

conda 4.6 Later version , Activate environment Use  conda activate


conda 4.6 Previous version , Activate environment Use :
Windows: activate
Linux and macOS: source activate

Environment exit

conda deactivate

Back to the default environment 844b2f2082e3cffd922903920f8b5dea.png

Environmental cloning

Copy an environment , The two configurations are the same , But it can operate independently

conda create --clone python2.7 --name new_python2.7# The environment python2.7 Clone a new_python2.7
f59ea7fb555b6ab0e9961d3965ab0df1.png

Environment delete

conda remove --name new_python2.7 --all# The environment new_python2.7 Delete 
71c7828d2dce35263c519167473636d3.png

5、Conda、pip And virtualenv Three more

  • conda Can be managed at the same time python Package and environment ;

  • pip Only management packs ;

  • virtualenv Can only manage the environment :https://www.liaoxuefeng.com/wiki/1016959663602400/1019273143120480

Taskconda Simultaneous management package and environmentpip management packageVirtualenv management environment
package install conda install $PACKAGE_NAMEpip install $PACKAGE_NAMEX
package to update conda update --name $ENVIRONMENT_NAME $PACKAGE_NAMEpip install --upgrade $PACKAGE_NAMEX
conda to update conda update condaLinux/macOS: pip install -U pip Win: python -m pip install -U pipX
package uninstall conda remove --name $ENVIRONMENT_NAME $PACKAGE_NAMEpip uninstall $PACKAGE_NAMEX
Create a new environmentconda create --name $ENVIRONMENT_NAME pythonXcd $ENV_BASE_DIR; virtualenv $ENVIRONMENT_NAME
Activate environmentconda activate $ENVIRONMENT_NAME*Xsource $ENV_BASE_DIR/$ENVIRONMENT_NAME/bin/activate
sign out environmentconda deactivateXdeactivate
Search available packagesconda search $SEARCH_TERMpip search $SEARCH_TERMX
Download... From the specified source packageconda install --channel $URL $PACKAGE_NAMEpip install --index-url $URL $PACKAGE_NAMEX
View installed packagesconda list --name $ENVIRONMENT_NAMEpip listX
establish project Requirements document conda list --exportpip freezeX
List all environmentsconda info --envsXInstall virtualenv wrapper, then lsvirtualenv
conda and pip Mutual installation conda install pippip install condaX
Install the specified version Pythonconda install python=x.xXX
Python upgrade conda update python*XX

Reference material

  • https://github.com/conda/conda

  • https://conda.io/projects/conda/en/latest/index.html#

-------- End --------

f8bb62fade46f7ef8ab6dbc5c6adb47a.png

bd896d2cdce5c9229263fdde0ca9ca9d.png

copyright notice
author[The way of Python data],Please bring the original link to reprint, thank you.
https://en.pythonmana.com/2022/131/202205111424167763.html

Random recommended