参考网址:http://blog.csdn.net/u010510350/article/details/72561761
1. Anaconda安装配置
安装过程参考我之前的Anaconda+Tensorflow+Theano+Keras安装博客。
由于墙的问题,用conda安装Pytorch过程中会连接失败,这是因为Anaconda.org的服务器在国外。在这里可以用清华TUNA镜像源,包含Anaconda仓库的镜像,将其加入conda的配置,配置如下:
# 添加Anaconda的TUNA镜像
$ conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
# TUNA的help中镜像地址加有引号,需要去掉
# 设置搜索时显示通道地址
$ conda config --set show_channel_urls yes
执行完上述命令后,会生成~/.condarc文件,记录着对conda的配置,直接手动创建、编辑该文件是相同的效果。
2. Pytorch安装
在这里的安装,我采用conda安装: $ conda install pytorch torchvision -c soumith
安装过程如下:
gjh@gjh-System-Product-Name:~$ conda install pytorch torchvision -c soumith
Fetching package metadata .............
Solving package specifications: .
Package plan for installation in environment /home/gjh/miniconda2:
The following NEW packages will be INSTALLED:
freetype: 2.8-hab7d2ae_1
intel-openmp: 2018.0.0-hc7b2577_8
jpeg: 9b-h024ee3a_2
libgcc: 7.2.0-h69d50b8_2
libpng: 1.6.32-hbd3595f_4
libtiff: 4.0.9-h28f6b97_0
mkl: 2018.0.1-h19d6760_4
numpy: 1.13.3-py27hbcc08e0_0
olefile: 0.44-py27h4bd3e3c_0
pillow: 4.3.0-py27h353bd0c_1
pytorch: 0.2.0-py27ha262b23_4cu75 soumith
torchvision: 0.1.9-py27hdb88a65_1 soumith
xz: 5.2.3-h55aa19d_2
Proceed ([y]/n)? y
intel-openmp-2 100% |################################| Time: 0:00:00 703.83 kB/s
jpeg-9b-h024ee 100% |################################| Time: 0:00:00 7.67 MB/s
libgcc-7.2.0-h 100% |################################| Time: 0:00:00 7.58 MB/s
mkl-2018.0.1-h 100% |################################| Time: 0:01:21 2.37 MB/s
xz-5.2.3-h55aa 100% |################################| Time: 0:00:00 1.20 MB/s
libpng-1.6.32- 100% |################################| Time: 0:00:00 1.81 MB/s
libtiff-4.0.9- 100% |################################| Time: 0:00:00 2.01 MB/s
freetype-2.8-h 100% |################################| Time: 0:00:00 2.01 MB/s
numpy-1.13.3-p 100% |################################| Time: 0:00:01 2.10 MB/s
olefile-0.44-p 100% |################################| Time: 0:00:00 2.75 MB/s
pillow-4.3.0-p 100% |################################| Time: 0:00:00 2.28 MB/s
pytorch-0.2.0-^C 2% | | Time: 0:00:04 2.15 MBpytorch-0.2.0- 100% |################################| Time: 0:00:04 66.05 MB/s
pytorch-0.2.0- 100% |################################| Time: 0:02:33 2.14 MB/s
torchvision-0. 100% |################################| Time: 0:00:00 14.84 MB/s
3. 测试
进入python模式下,看能否导入torch成功:
$ python
> import torch
gjh@gjh-System-Product-Name:~$ python
Python 2.7.14 |Anaconda, Inc.| (default, Oct 16 2017, 17:29:19)
[GCC 7.2.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import torch
>>>