Ubuntu16.04安装Pytorch

一.安装

1. 官方github:https://github.com/pytorch/pytorch

Install optional dependencies //安装依赖项

On Linux

export CMAKE_PREFIX_PATH="$(dirname $(which conda))/../" # [anaconda root directory]

# Install basic dependencies
conda install numpy pyyaml mkl setuptools cmake cffi

# Add LAPACK support for the GPU
conda install -c pytorch magma-cuda80 # or magma-cuda90 if CUDA 9



CondaError: CondaHTTPError When conda install -c soumith magma-cuda80=2.1.0 #1214

conda install magma-cuda80 -c soumith

- 出现网络错误

Downloading and Extracting Packages
certifi 2018.1.18: ##################################################### | 100% 
magma-cuda80 2.2.0:                                                      |   0% 

CondaHTTPError: HTTP 000 CONNECTION FAILED for url <https://conda.anaconda.org/pytorch/linux-64/magma-cuda80-2.2.0-h39f1f8d_1.tar.bz2>
Elapsed: -

An HTTP error occurred when trying to retrieve this URL.
HTTP errors are often intermittent, and a simple retry will get you on your way.

- 根据:Previous Versions

Installation instructions and binaries for previous PyTorch versions may be found on our website.

Installing with CUDA 8

conda install pytorch=0.1.12 cuda80 -c soumith

- 安装成功,但是运行出错

Downloading and Extracting Packages
cuda80 1.0: ############################################################ | 100% 
libgcc 7.2.0: ########################################################## | 100% 
pytorch 0.1.12: ######################################################## | 100% 
libtorch 0.1.12: ####################################################### | 100% 
openblas 0.2.19: ####################################################### | 100% 
Preparing transaction: done
Verifying transaction: done
Executing transaction: done
dsp@dsp:~$ python
Python 2.7.14 |Anaconda custom (64-bit)| (default, Oct 16 2017, 17:29:19) 
[GCC 7.2.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import torch
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/dsp/anaconda2/lib/python2.7/site-packages/torch/__init__.py", line 53, in <module>
    from torch._C import *
ImportError: /home/dsp/anaconda2/lib/python2.7/site-packages/torch/_C.so: undefined symbol: _ZN4thpp10THCSTensorIlEC1EP8THCStateP14THCSLongTensor
重新安装:conda install pytorch torchvision cuda80 -c soumith 后报错
>>> import torch
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/dsp/anaconda2/lib/python2.7/site-packages/torch/__init__.py", line 53, in <module>
from torch._C import *
ImportError: libiomp5.so: cannot open shared object file: No such file or directory
conda's anaconda channel packaging is faulty #2091: ImportError: libiomp5.so: cannot open shared object file

二.入门

此教程为翻译官方地址

Github 地址

简书地址

CSDN地址

作者:Soumith Chintala