PyTorch 安装(CUDA 是8.0以下旧版本,如何安装 pytorch?)

混江龙づ霸主 提交于 2020-08-19 13:03:28

PyTorch 官方安装命令合集

最近刚刚来到新的单位,分配了新的服务器。发现没有安装 pytorch,于是乎开始安装。

 

安装PyTorch正常方法

CUDA 低于 8.0 肿么办

附录

 


安装PyTorch正常方法

首先,先看看自己的 anaconda 里 Python  是什么版本的。直接输入指令:

$ python
Python 3.6.10 |Anaconda, Inc.| (default, May  8 2020, 02:54:21)
[GCC 7.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.

再检查自己的 cuda 版本

$ nvcc -V
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2016 NVIDIA Corporation
Built on Tue_Jan_10_13:22:03_CST_2017
Cuda compilation tools, release 8.0, V8.0.61

最后,去官网查看指令:https://pytorch.org/

进入官网,点击 ,进入下面界面:

根据自己的配置,选择相应指令。

 

CUDA 低于 8.0 肿么办

这时,我发现,这个界面里没有 CUDA 8.0 的指令了!肿么办?

注意到,上图中有个橙色的字体,告诉你如何下载以前的版本。

点击进入,可以找到自己的需要版本。

 

有两种方法安装,一种是用 conda 指令,一种是 pip 指令。

开始我用的是 conda,按照

conda install pytorch=0.4.1 cuda80 -c pytorch

发现报错:

Traceback (most recent call last):
  File "/root/anaconda3/bin/conda", line 7, in <module>
    from conda.cli import main
ModuleNotFoundError: No module named 'conda'

网上查找原因,说是 Python3.6 版本过高的原因。

重新安装 anaconda 毕竟很费劲。

想想,那就用 pip 安装呗。

官网有这么一段:

Via pip

Download the whl file with the desired version from the following html pages:

Then, install the file with pip install [downloaded file]

好了,这个就是我要找的了。

安装 pytorch 之后,别忘了安装 torchvision:

pip3 install torchvision

最后,进入Python,查看是否安装成功:

完工。

 

————————————————————————————————————————————————

附录

下面这个是从网上搜的一个博客,教你如何下载早版本 pytorch 的方法。请享用!

【转自】https://www.pytorchtutorial.com/pytorch-installation-commands/

 

文章目录 [隐藏]

Linux

使用 conda

以下命令适用于 Python 2.7 – 3.7。

CPU 版本:

conda install pytorch-cpu torchvision-cpu -c pytorch

1

conda install pytorch-cpu torchvision-cpu -c pytorch

CUDA 8:

conda install pytorch torchvision cuda80 -c pytorch

1

conda install pytorch torchvision cuda80 -c pytorch

CUDA 9.0:

conda install pytorch torchvision -c pytorch

1

conda install pytorch torchvision -c pytorch

CUDA 9.2:

conda install pytorch torchvision cuda92 -c pytorch

1

conda install pytorch torchvision cuda92 -c pytorch

 

使用 pip

Python 2.7

CPU 版本:

pip install http://download.pytorch.org/whl/cpu/torch-0.4.1-cp27-cp27mu-linux_x86_64.whl pip install torchvision # if the above command does not work, then you have python 2.7 UCS2, use this command pip install http://download.pytorch.org/whl/cpu/torch-0.4.1-cp27-cp27m-linux_x86_64.whl

1

2

3

4

5

pip install http://download.pytorch.org/whl/cpu/torch-0.4.1-cp27-cp27mu-linux_x86_64.whl

pip install torchvision

 

# if the above command does not work, then you have python 2.7 UCS2, use this command

pip install http://download.pytorch.org/whl/cpu/torch-0.4.1-cp27-cp27m-linux_x86_64.whl

CUDA 8:

pip install http://download.pytorch.org/whl/cu80/torch-0.4.1-cp27-cp27mu-linux_x86_64.whl pip install torchvision # if the above command does not work, then you have python 2.7 UCS2, use this command pip install http://download.pytorch.org/whl/cu80/torch-0.4.1-cp27-cp27m-linux_x86_64.whl

1

2

3

4

5

pip install http://download.pytorch.org/whl/cu80/torch-0.4.1-cp27-cp27mu-linux_x86_64.whl

pip install torchvision

 

# if the above command does not work, then you have python 2.7 UCS2, use this command

pip install http://download.pytorch.org/whl/cu80/torch-0.4.1-cp27-cp27m-linux_x86_64.whl

CUDA 9.0:

pip install torch torchvision

1

pip install torch torchvision

CUDA 9.2:

pip install http://download.pytorch.org/whl/cu92/torch-0.4.1-cp27-cp27mu-linux_x86_64.whl pip install torchvision # if the above command does not work, then you have python 2.7 UCS2, use this command pip install http://download.pytorch.org/whl/cu92/torch-0.4.1-cp27-cp27m-linux_x86_64.whl

1

2

3

4

5

pip install http://download.pytorch.org/whl/cu92/torch-0.4.1-cp27-cp27mu-linux_x86_64.whl

pip install torchvision

 

# if the above command does not work, then you have python 2.7 UCS2, use this command

pip install http://download.pytorch.org/whl/cu92/torch-0.4.1-cp27-cp27m-linux_x86_64.whl

 

Python 3.5

CPU 版本:

pip3 install http://download.pytorch.org/whl/cpu/torch-0.4.1-cp35-cp35m-linux_x86_64.whl pip3 install torchvision

1

2

pip3 install http://download.pytorch.org/whl/cpu/torch-0.4.1-cp35-cp35m-linux_x86_64.whl

pip3 install torchvision

CUDA 8:

pip3 install http://download.pytorch.org/whl/cu80/torch-0.4.1-cp35-cp35m-linux_x86_64.whl pip3 install torchvision

1

2

pip3 install http://download.pytorch.org/whl/cu80/torch-0.4.1-cp35-cp35m-linux_x86_64.whl

pip3 install torchvision

CUDA 9.0:

pip3 install torch torchvision

1

pip3 install torch torchvision

CUDA 9.2:

pip3 install http://download.pytorch.org/whl/cu92/torch-0.4.1-cp35-cp35m-linux_x86_64.whl pip3 install torchvision

1

2

pip3 install http://download.pytorch.org/whl/cu92/torch-0.4.1-cp35-cp35m-linux_x86_64.whl

pip3 install torchvision

 

Python 3.6

CPU 版本:

pip3 install http://download.pytorch.org/whl/cpu/torch-0.4.1-cp36-cp36m-linux_x86_64.whl pip3 install torchvision

1

2

pip3 install http://download.pytorch.org/whl/cpu/torch-0.4.1-cp36-cp36m-linux_x86_64.whl

pip3 install torchvision

CUDA 8:

pip3 install http://download.pytorch.org/whl/cu80/torch-0.4.1-cp36-cp36m-linux_x86_64.whl pip3 install torchvision

1

2

pip3 install http://download.pytorch.org/whl/cu80/torch-0.4.1-cp36-cp36m-linux_x86_64.whl

pip3 install torchvision

CUDA 9.0:

pip3 install torch torchvision

1

pip3 install torch torchvision

CUDA 9.2:

pip3 install http://download.pytorch.org/whl/cu92/torch-0.4.1-cp36-cp36m-linux_x86_64.whl pip3 install torchvision

1

2

pip3 install http://download.pytorch.org/whl/cu92/torch-0.4.1-cp36-cp36m-linux_x86_64.whl

pip3 install torchvision

 

Python 3.7

CPU 版本:

pip3 install http://download.pytorch.org/whl/cpu/torch-0.4.1.post2-cp37-cp37m-linux_x86_64.whl pip3 install torchvision

1

2

pip3 install http://download.pytorch.org/whl/cpu/torch-0.4.1.post2-cp37-cp37m-linux_x86_64.whl

pip3 install torchvision

CUDA 8:

pip3 install http://download.pytorch.org/whl/cu80/torch-0.4.1.post2-cp37-cp37m-linux_x86_64.whl pip3 install torchvision

1

2

pip3 install http://download.pytorch.org/whl/cu80/torch-0.4.1.post2-cp37-cp37m-linux_x86_64.whl

pip3 install torchvision

CUDA 9.0:

pip3 install torch torchvision

1

pip3 install torch torchvision

CUDA 9.2:

pip3 install http://download.pytorch.org/whl/cu92/torch-0.4.1.post2-cp37-cp37m-linux_x86_64.whl pip3 install torchvision

1

2

pip3 install http://download.pytorch.org/whl/cu92/torch-0.4.1.post2-cp37-cp37m-linux_x86_64.whl

pip3 install torchvision

 

MacOS

使用 conda

以下命令适用于 Python 2.7 – 3.7。

CPU 版本:

conda install pytorch torchvision -c pytorch

1

conda install pytorch torchvision -c pytorch

CUDA 8,CUDA 9.0,或 CUDA 9.2:MacOS 不支持 CUDA,如果需要,则需要从源码编译安装。

使用 pip

Python 2.7

CPU 版本:

pip install torch torchvision

1

pip install torch torchvision

CUDA 8,CUDA 9.0,或 CUDA 9.2:MacOS 不支持 CUDA,如果需要,则需要从源码编译安装。

Python 3.5,3.6,3.7

CPU 版本:

pip3 install torch torchvision

1

pip3 install torch torchvision

CUDA 8,CUDA 9.0,或 CUDA 9.2:MacOS 不支持 CUDA,如果需要,则需要从源码编译安装。

Windows

使用 conda

Python 2.7

PyTorch 不支持在 Windows 上的 Python 2.7 版本,请使用 Python 3 版本。

Python 3.5,3.6,3.7

CPU 版本:

conda install pytorch-cpu -c pytorch pip3 install torchvision

1

2

conda install pytorch-cpu -c pytorch

pip3 install torchvision

CUDA 8:

conda install pytorch cuda80 -c pytorch pip3 install torchvision

1

2

conda install pytorch cuda80 -c pytorch

pip3 install torchvision

CUDA 9.0:

conda install pytorch -c pytorch pip3 install torchvision

1

2

conda install pytorch -c pytorch

pip3 install torchvision

CUDA 9.2:

conda install pytorch cuda92 -c pytorch pip3 install torchvision

1

2

conda install pytorch cuda92 -c pytorch

pip3 install torchvision

 

使用 pip

Python 2.7

PyTorch 不支持在 Windows 上的 Python 2.7 版本,请使用 Python 3 版本。

Python 3.5

CPU 版本:

pip3 install http://download.pytorch.org/whl/cpu/torch-0.4.1-cp35-cp35m-win_amd64.whl pip3 install torchvision

1

2

pip3 install http://download.pytorch.org/whl/cpu/torch-0.4.1-cp35-cp35m-win_amd64.whl

pip3 install torchvision

CUDA 8:

pip3 install http://download.pytorch.org/whl/cu80/torch-0.4.1-cp35-cp35m-win_amd64.whl pip3 install torchvision

1

2

pip3 install http://download.pytorch.org/whl/cu80/torch-0.4.1-cp35-cp35m-win_amd64.whl

pip3 install torchvision

CUDA 9.0:

pip3 install http://download.pytorch.org/whl/cu90/torch-0.4.1-cp35-cp35m-win_amd64.whl pip3 install torchvision

1

2

pip3 install http://download.pytorch.org/whl/cu90/torch-0.4.1-cp35-cp35m-win_amd64.whl

pip3 install torchvision

CUDA 9.2:

pip3 install http://download.pytorch.org/whl/cu92/torch-0.4.1-cp35-cp35m-win_amd64.whl pip3 install torchvision

1

2

pip3 install http://download.pytorch.org/whl/cu92/torch-0.4.1-cp35-cp35m-win_amd64.whl

pip3 install torchvision

 

Python 3.6

CPU 版本:

pip3 install http://download.pytorch.org/whl/cpu/torch-0.4.1-cp36-cp36m-win_amd64.whl pip3 install torchvision

1

2

pip3 install http://download.pytorch.org/whl/cpu/torch-0.4.1-cp36-cp36m-win_amd64.whl

pip3 install torchvision

CUDA 8:

pip3 install http://download.pytorch.org/whl/cu80/torch-0.4.1-cp36-cp36m-win_amd64.whl pip3 install torchvision

1

2

pip3 install http://download.pytorch.org/whl/cu80/torch-0.4.1-cp36-cp36m-win_amd64.whl

pip3 install torchvision

CUDA 9.0:

pip3 install http://download.pytorch.org/whl/cu90/torch-0.4.1-cp36-cp36m-win_amd64.whl pip3 install torchvision

1

2

pip3 install http://download.pytorch.org/whl/cu90/torch-0.4.1-cp36-cp36m-win_amd64.whl

pip3 install torchvision

CUDA 9.2:

pip3 install http://download.pytorch.org/whl/cu92/torch-0.4.1-cp36-cp36m-win_amd64.whl pip3 install torchvision

1

2

pip3 install http://download.pytorch.org/whl/cu92/torch-0.4.1-cp36-cp36m-win_amd64.whl

pip3 install torchvision

 

Python 3.7

CPU 版本:

pip3 install http://download.pytorch.org/whl/cpu/torch-0.4.1-cp37-cp37m-win_amd64.whl pip3 install torchvision

1

2

pip3 install http://download.pytorch.org/whl/cpu/torch-0.4.1-cp37-cp37m-win_amd64.whl

pip3 install torchvision

CUDA 8:

pip3 install http://download.pytorch.org/whl/cu80/torch-0.4.1-cp37-cp37m-win_amd64.whl pip3 install torchvision

1

2

pip3 install http://download.pytorch.org/whl/cu80/torch-0.4.1-cp37-cp37m-win_amd64.whl

pip3 install torchvision

CUDA 9.0:

pip3 install http://download.pytorch.org/whl/cu90/torch-0.4.1-cp37-cp37m-win_amd64.whl pip3 install torchvision

1

2

pip3 install http://download.pytorch.org/whl/cu90/torch-0.4.1-cp37-cp37m-win_amd64.whl

pip3 install torchvision

CUDA 9.2:

pip3 install http://download.pytorch.org/whl/cu92/torch-0.4.1-cp37-cp37m-win_amd64.whl pip3 install torchvision

1

2

pip3 install http://download.pytorch.org/whl/cu92/torch-0.4.1-cp37-cp37m-win_amd64.whl

pip3 install torchvision

以上命令均为安装 PyTorch 的最新版本,要安装特定的老版本,请参考这个页面

还等什么,快点加入收藏吧!

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!