1.打開pytorch官網 https://pytorch.org/
2.選擇合適的選項
3.運行cmd命令提示符 運行 run this command里的內容
我用的是舊版本(pip install torch==1.4.0+cpu torchvision==0.5.0+cpu -f https://download.pytorch.org/whl/torch_stable.html)
4.在pycharm中import torch時顯示紅杠杠,是因為這個解釋器里沒有torch
選擇自己已存在的python解釋器
這里就有了
就不報錯了