1. Pytorch、Jupyter notebook的安装及环境配置
-
打开
Anaconda Prompt
-
创建虚拟环境:conda create -n pytorch_python39 python=3.9
-
激活环境:conda activate pytorch_python39
-
查看安装的包:pip list
-
清华源加速下的torch安装:pip install torch==1.8.1+cu102 torchvision==0.9.1+cu102 torchaudio==0.8.1 -f https://download.pytorch.org/whl/torch_stable.html -i https://pypi.tuna.tsinghua.edu.cn/simple
-
安装
jupyter_server
:conda install jupyter_server -
安装
nb_conda_kernels
:conda install nb_conda_kernels -
安装
ipykernel
:conda install ipykernel -
将环境注册到
Jupyter
:python -m ipykernel install --user --name=pytorch_python39 -
【前提是已经安装好Anaconda和python解释器,且有GPU并已经安装驱动,完成上述后即可在构建的虚拟环境中输入运行
jupyter notebook
】
2. 检测安装结果
-
检查pytorch在GPU下是否成功执行:在命令行窗口执行以下
conda activate pytorch_python39 python import torch torch.cuda.is_available() # 显示True则代表安装成功
-
检查jupyter notebook是否配置了我们的虚拟环境:在命令行窗口执行以下
conda activate pytorch_python39 jupyter notebook # 网址会打开,点击“NEW”,查看是否有虚拟环境