1.安裝anaconda
這個比較簡答直接上anaconda官網,點擊下載,然后按照步驟安裝即可;
anaconda官網:https://www.anaconda.com/products/individual
2.安裝pytorch
2.1 打開Anaconda prompt,依次輸入下面幾行代碼
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 --set show_channel_urls yes
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/
2.2 創建pytorch環境,輸入下面代碼,使用的python版本是3.7(其他版本的python應該也可以):
conda create -n pytorch python=3.7
2.3 根據要求輸入y即可,創建完之后,輸入下面的代碼:
activate pytorch
2.4 進入pytorch官網:
復制Run this Command中的內容,復制到命令行,刪除-c python,然后運行。
注意:在根據提示輸入y之后,安裝過程中可能會如下錯誤:
WARNING conda.gateways.disk.delete:unlink_or_rename_to_trash(143):
Could not remove or rename C:\Anaconda3\pkgs\pytorch-1.11.0-py3.7_cuda11.3_cudnn8_0\Lib\site-packages\torch\lib\cudnn_ops_train64_8.dll.
Please remove this file manually (you may need to reboot to free file handles)
出現這個錯誤的話就需要你跟據給出的地址手動去刪除這個文件,
C:\Anaconda3\pkgs\pytorch-1.11.0-py3.7_cuda11.3_cudnn8_0\Lib\site-packages\torch\lib\cudnn_ops_train64_8.dll
2.5 退出去后再打開Anaconda prompt,進入pytorch環境,再輸入從pytorch官網復制過來的代碼(去掉-c pytorch):
運行后可能還會報錯,如下所示:
CondaVerificationError: The package for pytorch located at C:\Anaconda3\pkgs\pytorch-1.11.0-py3.7_cuda11.3_cudnn8_0 appears to be corrupted. The path 'Lib/site-packages/torch/include/ATen/ops/zeros_compositeimplicitautograd_dispatch.h' specified in the package manifest cannot be found.
如果有上述錯誤,則輸入下述代碼
conda clean --all
然后退出去再重復一次2.5的操作,就可以安裝成功了。
上面是我自己安裝pytorch過程中所遇到的問題,以及對應的解決方法,供大家參考。