在网上看到的比较多的方法是用Anaconda安装,这里介绍用pip安装的方法。

1 登录pytorch官网生成安装链接

pytorch官网网址:

https://pytorch.org/get-started/locally/

选择自己的设置,如下图:

在这里插入图片描述
注意:

对于CUDA,我选择的是None。根据自己电脑性能的不同,可以自由选择。

关于CUDA的选择,可以参考:

https://blog.csdn.net/Mind_programmonkey/article/details/99688839/

在设置好参数后,Run this Command:则会给出相应的命令,将该命令复制到命令行执行即可。

2 执行命令

C:\Users\zy>pip install torch==1.6.0+cpu torchvision==0.7.0+cpu -f https://download.pytorch.org/whl/torch_stable.html
Looking in links: https://download.pytorch.org/whl/torch_stable.html
Collecting torch==1.6.0+cpu
  Downloading https://download.pytorch.org/whl/cpu/torch-1.6.0%2Bcpu-cp38-cp38-win_amd64.whl (167.7 MB)
     |████████████████████████████████| 167.7 MB 31 kB/s
Collecting torchvision==0.7.0+cpu
  Downloading https://download.pytorch.org/whl/cpu/torchvision-0.7.0%2Bcpu-cp38-cp38-win_amd64.whl (362 kB)
     |████████████████████████████████| 362 kB 1.3 MB/s
Requirement already satisfied: numpy in e:\python\lib\site-packages (from torch==1.6.0+cpu) (1.19.1)
Collecting future
  Downloading future-0.18.2.tar.gz (829 kB)
     |████████████████████████████████| 829 kB 726 kB/s
Requirement already satisfied: pillow>=4.1.1 in e:\python\lib\site-packages (from torchvision==0.7.0+cpu) (7.2.0)
Using legacy 'setup.py install' for future, since package 'wheel' is not installed.
Installing collected packages: future, torch, torchvision
    Running setup.py install for future ... done
Successfully installed future-0.18.2 torch-1.6.0+cpu torchvision-0.7.0+cpu

显示已成功安装pytorch。

3 检验是否安装成功

在CMD执行命令:

import torch
print(torch.version)

import torchvision
print(torchvision.version)

不报错则说明安装成功,如下图。

C:\Users\zy>python
Python 3.8.5 (tags/v3.8.5:580fbb0, Jul 20 2020, 15:57:54) [MSC v.1924 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import torch
>>> print(torch.__version__)
1.6.0+cpu
>>> import torchvision
>>> print(torchvision.__version__)
0.7.0+cpu

4 说明

若觉得下载网速过慢,可以将得到的链接(Download https:里面已给出)用下载工具下载到本地,然后自行安装。

  1. pip install filepath
    filepath代表是刚刚下载资源的路径
    如:F:\Download\torch-1.6.0%2Bcpu-cp38-cp38-win_amd64.whl

pytorch安装结束后,我们安装对应的torchvision。

这个文件很小(几百k),使用官网Run this Command给出的命令即可.

但要注意去掉前面的torch:

  1. pip install torchvision==0.7.0+cpu -f https://download.pytorch.org/whl/torch_stable.html

即可完成安装。

也可类似上一步一样根据Download https:给出的链接下载到本地,然后自行安装。

Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐