一、确保anaconda安装好
使用下列命令检测conda版本
conda --version
二、查看conda局部环境
conda env list
三、(可选)配置Pytorch镜像源
设置清华源
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 --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/
conda config --set show_channel_urls yes
查看设置
conda config --show channels
四、创建新的conda环境并命名为Pytorch
conda create -n pytorch python=3.8.20
C:\Users\zzy>conda env list
# conda environments:
#
base * D:\Anaconda3\Anaconda3
pytorch D:\Anaconda3\Anaconda3\envs\pytorch
五、激活环境
conda activate pytorch
输入可能会遇到报错
C:\Users\zzy>conda activate pytorch
CommandNotFoundError: Your shell has not been properly configured to use 'conda activate'.
If using 'conda activate' from a batch script, change your
invocation to 'CALL conda.bat activate'.
To initialize your shell, run
$ conda init <SHELL_NAME>
Currently supported shells are:
- bash
- cmd.exe
- fish
- tcsh
- xonsh
- zsh
- powershell
See 'conda init --help' for more information and options.
IMPORTANT: You may need to close and restart your shell after running 'conda init'.
转为使用这条命令
CALL conda.bat activate pytorch
得到这种命令行:(pytorch) C:\Users\zzy>
六、在虚拟环境中安装 ipykernel
ipykernel
能够让 Jupyter Notebook 识别到该虚拟环境。在激活的虚拟环境中执行以下命令进行安装:
conda install ipykernel
七、将虚拟环境添加到 Jupyter Notebook
python -m ipykernel install --user --name pytorch --display-name "Python (pytorch)"
评论区