创建虚拟环境并激活
conda create -n Your_name python=3.6
conda activate Your_name
查询torch官网
https://pytorch.org/
各种安装版本都在这里 https://pytorch.org/get-started/previous-versions/
安装cuda
在pycharm终端输入下面命令
conda install cudatoolkit=10.2
安装cudaa
在pycharm终端输入下面命令
conda install cudnn=7.6.5
第一种方法(推荐)
切换到国内源
https://blog.youkuaiyun.com/weixin_34910922/article/details/116721774
推荐使用中科大的源
然后复制那个 pytorch的 官网命令
conda install pytorch torchvision torchaudio cudatoolkit=10.2 -c pytorch
第二种方法
torch下载界面
http://download.pytorch.org/whl/torch_stable.html
2.1.搜索torch-1.8并下载amd64.whl cp36代表python3.6版本
2.2.搜索torchvision-0.9.0并下载amd64.whl cp36代表python3.6版本
2.3.下载后放到一个文件夹里面
2.4 安装torch
输入pip install troch(空格自动填充)
输入pip install torchvision(空格自动填充)
pip install torch-1.8.0-cp36-cp36m-win_amd64.whl
pip install "torchvision-0.9.0+cpu-cp36-cp36m-win_amd64.whl"
验证torch(通用)
import torch
print("hello pytorch {}".format(torch.__version__))
print(torch.cuda.is_available())
print(torch.cuda.get_device_name(0))