Preface
Use conda to directly create virtual environments of different python versions and configure them, which is more flexible and easy to use.
1. Create a virtual environment
Create xxx
a virtual environment named, specify the Python version of the virtual environment as 3.9
conda create -n xxx python=3.9
2. Enter the virtual environment
conda activate xxx
#or
activate xxx
3. Exit the virtual environment
conda deactivate
4. View the virtual environment
Check what virtual environments exist locally
conda info --env
# or
conda env list
5. Delete the virtual environment
Delete xxx
the virtual environment named. Sometimes one of them will report an error, but it will be fine if you replace it with the other one. I still don’t understand why.
conda remove -n xxx --all
# or
conda env remove --name xxx
6. Copy the virtual environment
It’s really easy to use and very convenient. I used the server in the study room for the first time and directly copied the environment configured by the boss, haha
conda create -n 新环境名 --clone 旧环境名
To copy the Anaconda virtual environment to other machines, see here
Migrate the anaconda virtual environment
7. Packages in a certain environment
conda activate xxx
conda list
# or
conda list -n xxx
8. package
# 查找package信息
conda search numpy
# 安装package
conda install -n xxx numpy
# 如果不用-n指定环境名称,则被安装在当前激活环境
# 也可以通过-c指定通过某个channel安装
# 更新package
conda update -n xxx numpy
# 删除package
conda remove -n xxx numpy