本文安装依赖的环境为Ubuntu14.04、python2.7、cuda8.0、cudnn7.0、opencv2.4.10,这些环境安装不再赘述,网上教程很多。
1、更新pip(很重要,为第2步做准备)
下载最新pip源码包,pip官网https://pypi.org/project/pip/,pip源码包下载地址https://github.com/pypa/pip
unzip pip-master.zip
cd pip-master
sudo python setup.py install
2、安装PyTorch
到pytoch官网(https://pytorch.org,有时候需要翻墙才能连接上)选择Linux、pip、python2.7、cuda8.0下载whl安装包或者直接从链接http://download.pytorch.org/whl/cu80/torch-0.4.1-cp27-cp27mu-linux_x86_64.whl上下载(不需要翻墙),然后执行
sudo pip install torch-0.4.1-cp27-cp27mu-linux_x86_64.whl
注:如果不根据第1步更新pip,则用pip安装pytorch时会报“torch-0.4.1-cp27-cp27mu-linux_x86_64.whl is not a supported wheel on this platform”的错误
3、安装torchvision
sudo pip install torchvision
注:如果安装过程中提示需要更新Pillow,但出现网络超时更新失败,有两种解决办法:
(1)可以根据链接手动下载Pillow最新源码包,通过源码安装Pillow
(2)或者更新pip源(这个网络介绍较多,这儿不再赘述),或者直接用其他源安装torch(例如用清华源安装,sudo pip install torchvision -i https://pypi.tuna.tsinghua.edu.cn/simple)