一、创建虚拟环境
Anaconda个人版(以前称为Anaconda发行版)2020.02版本中默认的python版本是3.7,但同时提供了python3.6和python3.8的元软件包。
想将python3.7切换为python3.6或python3.8,请执行如下命令:
conda create -n py36 anaconda=2020.02 python=3.6
conda create -n py38 anaconda=2020.02 python=3.8
执行命令后的运行情况大致如下:
Collecting package metadata (current_repodata.json): done
Solving environment: failed with repodata from current_repodata.json, will retry with next repodata source.
Collecting package metadata (repodata.json): done
Solving environment: done
## Package Plan ##
environment location: /root/anaconda3/envs/py36
added / updated specs:
- anaconda=2020.02
- python=3.6
The following packages will be downloaded:
The following NEW packages will be INSTALLED:
Preparing transaction: done
Verifying transaction: done
Executing transaction: done
#
# To activate this environment, use
#
# $ conda activate py36
#
# To deactivate an active environment, use
#
# $ conda deactivate
至此python3.6环境安装成功。运行中途会询问你是否继续(Proceed ([y]/n)?),输入y即可。
启用python3.6,输入命令:
conda activate py36
停用python3.6,输入命令:
conda deactivate
二、拓展部分 - 删除虚拟环境
先停用虚拟环境:
conda deactivate
然后查看虚拟环境及所在路径:
conda env list
最后删除指定的虚拟环境,-p后面是所要删除的虚拟环境的路径:
conda env remove -p /home/xxx/.conda/envs/py36
另一种删除指定的虚拟环境的方法,-n后面是所要删除的虚拟环境名:
conda remove -n py36 --all
参考:
[1]Team Anaconda.Anaconda Individual Edition 2020.02: New Name, Exciting Features[EB/OL].https://www.anaconda.com/blog/anaconda-individual-edition-2020-02-new-name-exciting-features ,MAR 11, 2020.