没有科学上网工具就别尝试pytorch官网给出的安装方案了,网速跟不上.没这金刚钻揽啥瓷器活!!!
通过国内镜像安装方式如下:
先看自己CUDA对应的torch版本,然后:
pip install --default-timeout=100 -i https://mirrors.aliyun.com/pypi/simple torch==1.2.0
–default-timeout=100 表示延迟,如果网速跟不上,加入这个参数.
torch==1.2.0是我要下载的版本
问题1: 如果下载完torch后,附带的numpy等包没下完就突然断开连接,那么再继续使用上一条命令下载可能会报错.
Expected sha256 a13bf6f78a49d844b85c142b8cd62d2e1833a11ed21ea0bc6b1ac73d24c76415
Got 58c19649b1b84c9bb1847e92a70d500ce616486f1c39cd399eb3de7d157fdd8a
此时,解决办法是下载另外一个版本的torch,下载完成后再卸载,然后再重新下载1.2.0版本。
改进上一条命令,多加一个 –upgrade ,也就是下载最新版本的torch。并且删除指定版本(删除==1.2.0
),直接用torch代替.
注意:这时下载,版本会更改为最新版本.
pip install --default-timeout=100 --upgrade -i https://mirrors.aliyun.com/pypi/simple torch
问题2: 假如这时才下载一半, 突然网速很慢,出现断连问题,可能需要替换之前的镜像源:
清华源: https://pypi.tuna.tsinghua.edu.cn/simple
中科大源: https://pypi.mirrors.ustc.edu.cn/simple
阿里云源: https://mirrors.aliyun.com/pypi/simple
总有一个适合你, 亲测阿里云最快,且下载成功。
如前面所说,需要卸载最新版本,再重装指定版本,镜像源也要改为上一步能成功下载的镜像:
pip uninstall torch
pip install --default-timeout=100 -i https://mirrors.aliyun.com/pypi/simple torch==1.2.0
安装完成后测试是否安装成功,在终端输入python,再输入import torch,如果没报错,那么安装成功。
(pytorch) jim@jim-Vostro-3670:~$ python
Python 3.5.5 | packaged by conda-forge | (default, Jul 23 2018, 23:45:43)
[GCC 4.8.2 20140120 (Red Hat 4.8.2-15)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import torch
>>>
另外,还需要安装torchvision,注意torchvision与torch的版本对应关系:
pip install -i https://mirrors.aliyun.com/pypi/simple torchvision==0.4.0
同理,测试是否安装成功:
>>> import torchvision
>>>