Summary of commonly used conda/pip commands [commands related to environment creation, source addition and deletion, and package operations]

1. Conda environment related commands

1.conda new environment command

conda create -n env_name python=x.x

env_name is the environment name, replace it with the name of the virtual environment to be created
python=xx is the version number, such as 3.7, 3.8

2. View all virtual environments in the conda environment

conda info -e
conda env list

The two commands are equivalent

3. conda delete the entire environment command

conda remove -n env_name --all

env_name The name of the virtual environment to be deleted

4. Conda activates the virtual environment

conda activate env_name

5. conda exits the current virtual environment

conda deactivate

6. Modify the python version

python --version 

Check the python version
to activate the environment

conda install python=x.x

You can modify the conda version in the environment, but this modification is not recommended, there will be problems with many dependencies, it is best to delete the environment and re-create the python version

2. Conda source related commands

1. View the channel configuration of conda

conda config --show channels

2. conda add source

conda config --add channels http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
conda config --add channels http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
conda config --add channels http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/mro
conda config --add channels http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/msys2
conda config --add channels http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/pro
conda config --add channels http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r

This is the mirror gateway of Tsinghua UniversityI found a problem. The source of Tsinghua University was the source of Beijing Foreign Studies University. I checked and explained that the source of Beijing Foreign Studies University was provided by the source of Tsinghua University. The essence is the same.
Here is a photo of access to Tsinghua's full source aboveinsert image description hereFor convenience, it is recommended to add all the sources in the Tsinghua directory, and Tsinghua has the most resources, so it is not easy for some sources to be missing.

3. conda deletes the specified source

conda delete source screenshot

conda config --remove channels http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r

The following is the source that needs to be deleted, do not add '', "" these symbols

4. conda delete all sources

common mistakesIt can be seen from the above picture that conda's prompt --remove requires two parameters key and value. And --remove-key only needs a key parameter, so remove all sources using the --remove-key command

conda config --remove-key channels

conda removes all sources

3. Conda package related commands

1. View the packages in the virtual environment

conda list
pip list

The difference between pip and conda is as follows

The difference between pip and conda

2. Check if a package is included

conda list xxx

xxx is not necessarily the complete package name, just a few subtitles, support fuzzy query

3. conda/pip download package (including downloading from the requirements.txt file)

conda install pkg_name
pip install pkg_name 
conda install pkg_name=x.x
pip --default-timeout=100 install pkg_name

pkg_name is the package name, =xx can specify the version of the package
–default-timeout sets the default time, the unit is s

If it is a project on github, there will generally be a requirements.txt file, which will contain the packages required by this project.

insert image description here
insert image description here
You can download the github project locally, then switch to the directory where requirements.txt is located (very important) and execute the following command

 pip install -r requirements.txt

All packages under this file will be downloaded automatically

4. conda uninstall package

conda uninstall xxx
pip uninstall xxx

It should be noted here, what command to use to install is best to use what command to uninstall, otherwise problems will easily occur

5. Update package

conda update --all 
conda update pkg_name

Update all
Update the specified version of the package

Four, pip package related commands

1. Download package

When pip downloads the package, due to various reasons, the download may fail. At this time, you can use the command to change the source, as follows, half of which can solve the download problem.

pip install ipywidgets -i http://pypi.douban.com/simple --trusted-host pypi.douban.com

Guess you like

Origin blog.csdn.net/syucsdn/article/details/128392707