Common commands of conda: install, update, create, activate, close, view, uninstall, delete, clean, rename, change source, problem

download

Go directly to the anaconda official website to download the installation file, and search the specific website by yourself.
The official website provides linux version, windows version, mac version.
At the same time, the full version of Anaconda and the minimal version of miniconda are provided (no software interface, only command line execution is supported). The Anaconda version is recommended for beginners. After familiarity, it is recommended to use the miniconda version, which takes up less storage space and feels the same when using it.

Install

Linux environment

bash Anaconda3-2019.07-Linux-x86_64.sh
 #yes+Enter 
#Then restart the terminal
  • 1
  • 2
  • 3

Window environment: Double-click the installation exe file directly, and then install it according to the installation wizard

upgrade

Upgrading Anaconda requires upgrading conda first

conda update conda #basic           upgrade 
conda update anaconda #big        upgrade
conda update anaconda-navigator //update the latest version of anaconda-navigator   
  • 1
  • 2
  • 3

Uninstall Anaconda software

Since Anaconda's installation files are all contained in a directory, you can delete the directory directly. Delete the entire Anaconda directory:

Computer Control Panel -> Programs and Apps -> Uninstall //windows

or

Find C:\ProgramData\Anaconda3\Uninstall-Anaconda3.exe to uninstall

rm -rf anaconda //free
  • 1

Finally, it is recommended to clean up the Anaconda path in .bashrc.

The conda environment uses basic commands

conda update -n base conda         #update the latest version of conda 
conda update --all                 #update the latest version of conda 
conda create -n xxxx python = 3.5    #Create a xxxx virtual environment 
for python3.5 conda activate xxxx                #Open the xxxx environment 
conda deactivate                   # Close the environment 
conda env list                     #Show all virtual environments 
conda info --envs #Show                  all virtual environments
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

View the installable version information of the specified package command

Check out the various versions of tensorflow : (You will find that there are a lot of TensorFlow sources, but you can't choose them casually. You can use the find command to locate them if you choose)

conda search -h #View search help information
conda search tensorflow  
  • 1
  • 2

View the installable version information of the specified package command

anaconda show <USER/PACKAGE>  
  • 1

View the specified anaconda/tensorflow version information

conda show tensorflow
  • 1

The output will provide a download address, use the following command to specify the installation of version 1.8.0 tensorflow

conda install --channel https://conda.anaconda.org/anaconda tensorflow=1.8.0 
  • 1

Update, uninstall the installation package:

conda list #View          the installed packages 
conda list -n xxx #Specify        to view the packages installed in the xxx virtual environment 
conda update xxx #Update    the xxx file package 
conda uninstall xxx #Uninstall    the xxx file package
  • 1
  • 2
  • 3
  • 4

delete virtual environment

conda remove -n xxxx --all //Create a xxxx virtual environment
  • 1

clean up (conda slim down)

conda clean can be done easily! The first step: remove some useless packages through conda clean -p, this command will check which packages are not hard-dependent to other places in the package cache, and delete them. Step 2: You can delete the tar package saved by conda through conda clean -t.

conda clean -p //delete useless packages
conda clean -t //delete the tar package
conda clean -y --all //delete all installation packages and cache
  • 1
  • 2
  • 3

Reference: http://www.ifindbug.com/doc/id-48904/name-conda-common-commands-to-organize.html

copy/rename/delete env environment

Conda doesn't have the ability to rename environments, and the only way to achieve this basic need is through a stupid clone-delete process.
Remember not to directly mv move the environment folder to rename, it will lead to a series of unimaginable errors!

//Clone the oldname environment to the newname environment
conda create --name newname --clone oldname 
// completely delete the old environment
conda remove --name oldname --all      
  • 1
  • 2
  • 3
  • 4

Note: The above operations must be performed in the base environment, otherwise various inexplicable problems will occur.

conda auto on/off activation

Reference: http://www.ifindbug.com/doc/id-48908/name-after-installing-conda-cancel-the-base-that-appears-before-the-command-line-cancel-the-basic-environment-that-automatically-activates-conda-each-time-you-start-and-use-the-python-environment-that-comes-with-ubuntu.html

conda activate #Activate    the base environment by default 
conda activate xxx   #Activate the xxx environment 
conda deactivate #Close the current environment 
conda config --set auto_activate_base false #Close the   automatic activation state 
conda config --set auto_activate_base true #Close   the automatic activation state
  • 1
  • 2
  • 3
  • 4
  • 5

Conda install local package

Sometimes the download speed of conda or pip source is too slow, and the connection will be interrupted during the install a process, resulting in incomplete download of the compressed package.
At this time, we can use the browser and other tools to download the specified package first and then use conda or pip for local installation

#pip install local package 
pip install    ~/Downloads/a.whl
 #conda install local package 
conda install --use-local ~/Downloads/a.tar.bz2
  • 1
  • 2
  • 3
  • 4

Solve the slow download speed of conda/pip install

conda data source management

#Display the current data sources of conda
conda config --show channels
#Add data source: For example, add Tsinghua anaconda image:
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 #delete 
data source
conda config --remove channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

record it

#My ~/.condarc 
auto_activate_base: false
channels:
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/menpo/
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/bioconda/
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/msys2/
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
show_channel_urls: true
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11

pip data source management

#Display the current data sources of pip
pip config list
pip config list -- [ user | global ]  # List users | global settings 
pip config get global.index-url # Get the value corresponding to this key such as: https://mirrors.aliyun.com/pypi/simple/

# Add 
pip config set key value
 #Add data source: For example, add the source of USTC University of Science and Technology: 
pip config set global.index-url https://mirrors.ustc.edu.cn/pypi/web/simple #Add
 global use of this Data source 
pip config set global.trusted-host https://mirrors.ustc.edu.cn/pypi/web/simple

# delete 
pip config unset key
 # eg
conda config --remove channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/

#Search 
pip search flask #Search   flask installation package

# Upgrade pip 
pip install pip -U
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22

Record the domestic source of pip

Aliyun http://mirrors.aliyun.com/pypi/simple/
University of Science and Technology of China https://pypi.mirrors.ustc.edu.cn/simple/
Douban ( douban )          http://pypi.douban.com/simple/
Tsinghua University https://pypi.tuna.tsinghua.edu.cn/simple/
University of Science and Technology of China http://pypi.mirrors.ustc.edu.cn/simple/
  • 1
  • 2
  • 3
  • 4
  • 5

pip installation package management

pip list #List currently cached packages 
pip purge #Clear cache 
pip remove #Delete the corresponding cache 
pip help  #Help 
pip install xxx #Install xxx package 
pip install xxx.whl #Install xxx.whl local package 
pip uninstall xxx #Delete xxx Package 
pip show xxx #Display the specified installed xxx package 
pip check xxx #Check whether the dependencies of the xxx package are appropriate
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

pip and conda batch export and install components (requirements.txt)

refer to

Common software installation

Reference: Common software installation in conda environment

question

1:failed ERROR conda.core.link:_execute(502):

The following error message appears when conda install software:
Preparing transaction: done
Verifying transaction: done
Executing transaction: 
failed ERROR conda.core.link:_execute(502):
  • 1
  • 2
  • 3
  • 4
  • 5

Solution: Sometimes the permissions are not enough, you need to run the Anaconda prompt as an administrator to install

2. anaconda or conda is not an internal command

Solution: https://zhuanlan.zhihu.com/p/32446675 Just
insert image description here
add the environment variable above

jupyter notebook default working directory setting
Reference: http://www.ifindbug.com/doc/id-48907/name-change-the-default-working-directory-for-jupyter-notebooks.html

1) Enter the following command in the Anaconda Prompt terminal to see where your notebook configuration file is:

jupyter notebook --generate-config #The
 file C:\Users\user\.jupyter\jupyter_notebook_config.py will be generated
  • 1
  • 2

2) Open the jupyter_notebook_config.py file by searching for keywords: c.NotebookApp.notebook_dir, and modify it as follows

c.NotebookApp.notebook_dir =  'E:\\tf_models'      //Modify to custom folder
  • 1

3) Then restart the notebook server.

**Note: **Other methods directly command to the specified directory, enter in the Anaconda Prompt terminal: jupyter notebook directory address

3. When conda creates an environment, an error occurs: NotWritableError: The current user does not have write permissions to a required path.

The main reason for the problem: the user does not have read and write permissions to the .conda folder, which is caused by the use of administrator permissions when installing conda.

sudo  chown -R xxx:xxx .conda     #xxx is your own username/group
  • 1

4. An error is reported when conda creates an environment: Collecting package metadata (current_repodata.json): failed ProxyError: Conda cannot proceed due to an error in your proxy configuration.

Reason: mainly when conda install xxx, use Ctrl+C to forcibly interrupt the installation of xxx software, and then modify the PC network connection method (the proxy connection is changed to the direct connection method)

env  |  grep -i "_PROXY" #You 
can see that it is still the original proxy connection method 
#Solution: 
# Close the current terminal, reopen the new terminal, and then solve the problem
  • 1
  • 2
  • 3
  • 4

Tags: Common commands of conda: install, update, create, activate, close, view, uninstall, delete, clean, rename, change source, problem

IDE tools python conda conda

Related: Common commands of conda: install, update, create, activate, close, view, uninstall, delete, clean, rename, change source, problem