1 查看已经创建的虚拟环境
conda info --env  或 conda info -e
 
  | 
 
2 创建虚拟环境
conda create -n env_1 python=3.8
 
  | 
 
3 进入(激活)虚拟环境
4 更换国内镜像源
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
 
  | 
 
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
 
  | 
 
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/msys2/
 
  | 
 
5 安装、卸载、更新各种第三方包(3选1)
安装
pip install numpy==1.17.0
 
  | 
 
pip3 install numpy==1.17.0
 
  | 
 
conda install numpy==1.17.0
 
  | 
 
卸载
更新
conda update numpy==1.16.0
 
  | 
 
6 激活、退出、删除虚拟环境
激活
退出
删除
conda remove -n env_1 --all
 
  | 
 
7 查看虚拟环境信息
查看所有已安装包
查看配置
8 配置Jupyter Notebook
设置jupyter notebook在虚拟环境中运行
ipython kernel install --user --name=env_1
 
  | 
 
查看安装的内核和位置
移除指定kernel
jupyter kernelspec remove env_1
 
  | 
 
jupyter notebook代码补全功能
安装Nbextensions插件
pip install jupyter_contrib_nbextensions -i https://pypi.tuna.tsinghua.edu.cn/simple
 
  | 
 
jupyter contrib nbextension install --user --skip-running-check
 
  | 
 
打开Jupyter Notebook
勾选Hinterland即可,记得Disable Configuration……
如果代码补全功能不能用,请执行以下代码
conda install jedi==0.17.0
 
  | 
 
把env_1换成自己创建的就行
再打开jupyter notebook新建文件可以看到虚拟环境
9 保存虚拟环境
导出conda的包,注意是当前环境
conda env export > test.yaml
 
  | 
 
导出pip的包
pip freeze > requirements.txt
 
  | 
 
10 导入虚拟环境
(1)载入虚拟环境
conda env create -f test.yaml
 
  | 
 
(2)进入该环境
(3)加载pip包
pip install -r requirements.txt
 
  | 
 
11 安装pytorch
选择合适的版本: https://pytorch.org/get-started/locally/
12 检验pytorch是否安装成功
import torch print(torch.__version__) print("gpu", torch.cuda.is_available())
 
  |