Anaconda

1 minute read

Published:

Anaconda Environment Issues

Check environment information: conda info -e
Create a new environment: conda create --name environment_name python=3.7
Create an environment and add a package: conda create --name environment_name package_name
Remove an environment: conda remove -n environment_name --all
Switch to an environment: conda activate environment_name
Exit an environment: conda deactivate
Export package names in the environment: conda env export --name environment_name > export_name.yaml
Install packages in bulk: conda install --yes --file base.txt

Conda Package Installation

Install a package: conda install package_name
Update a package: conda update package_name
Update some packages: conda update numpy scipy pandas
Update all packages: conda update --all
Uninstall a package: conda remove package_name
View installed packages: conda list
Upgrade Anaconda: conda update anaconda

Add Domestic Mirror Source for Conda

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

Switch back to default source

conda config --remove-key channels

Pip Package Installation

Install a package: pip install package_name
View packages that need updating: pip list --outdated
Update a package: pip install -U package_name or pip install --upgrade package_name
Uninstall a package: pip uninstall package_name
View installed packages: pip list
Export environment: pip list --format=freeze > requirements.txt
Install packages in bulk via requirements file: pip install -r requirements.txt
Uninstall software packages in bulk via requirements file: pip uninstall -r requirements.txt
Conda package installation is safer compared to pip, as it automatically resolves package configuration issues, but it is relatively slower.

Change Pip to Domestic Mirror Source

Temporary use: You can add the -i parameter after using pip to specify the pip source

pip install scrapy -i https://pypi.tuna.tsinghua.edu.cn/simple

Permanent modification: Linux: Modify ~/.pip/pip.conf (create one if it doesn’t exist), content as follows:

[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple

Windows: Directly create a pip directory in the user directory, such as: C:\Users\xx\pip, create a new file pip.ini, content as follows

[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple

Change Setup to Domestic Mirror Source

Method One: Modify the ~/.pydistutils.cfg file vim ~/.pydistutils.cfg to:

[easy_install]
index_url = https://pypi.tuna.tsinghua.edu.cn/simple

Method Two: Directly place a setup.cfg in the same directory as setup.py:

[easy_install]
index_url = https://pypi.tuna.tsinghua.edu.cn/simple