安装pytorch命令

网址:https://pytorch.org/get-started/previous-versions/

INSTALLING PREVIOUS VERSIONS OF PYTORCH

We’d prefer you install the latest version, but old binaries and installation instructions are provided below for your convenience.

# 配置国内源,安装PyTorch用
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/

COMMANDS FOR VERSIONS >= 1.0.0

v1.2.0

Conda

OSX

# conda
conda install pytorch==1.2.0 torchvision==0.4.0 -c pytorch

Linux and Windows

# CUDA 9.2
conda install pytorch==1.2.0 torchvision==0.4.0 cudatoolkit=9.2 -c pytorch

# CUDA 10.0
conda install pytorch==1.2.0 torchvision==0.4.0 cudatoolkit=10.0 -c pytorch

# CPU Only
conda install pytorch==1.2.0 torchvision==0.4.0 cpuonly -c pytorch

Wheel

OSX

pip install torch==1.2.0 torchvision==0.4.0

Linux and Windows

# CUDA 10.0
pip install torch==1.2.0 torchvision==0.4.0 -f https://download.pytorch.org/whl/torch_stable.html

# CUDA 9.2
pip install torch==1.2.0+cu92 torchvision==0.4.0+cu92 -f https://download.pytorch.org/whl/torch_stable.html

# CPU only
pip install torch==1.2.0+cpu torchvision==0.4.0+cpu -f https://download.pytorch.org/whl/torch_stable.html

v1.1.0

Conda

OSX

# conda
conda install pytorch==1.1.0 torchvision==0.3.0 -c pytorch

Linux and Windows

# CUDA 9.0
conda install pytorch==1.1.0 torchvision==0.3.0 cudatoolkit=9.0 -c pytorch

# CUDA 10.0
conda install pytorch==1.1.0 torchvision==0.3.0 cudatoolkit=10.0 -c pytorch

# CPU Only
conda install pytorch-cpu==1.1.0 torchvision-cpu==0.3.0 cpuonly -c pytorch

Wheel

OSX

pip install torch==1.1.0 torchvision==0.3.0

Linux and Windows

# CUDA 10.0
Download and install wheel from https://download.pytorch.org/whl/cu100/torch_stable.html

# CUDA 9.0
Download and install wheel from https://download.pytorch.org/whl/cu90/torch_stable.html

# CPU only
Download and install wheel from https://download.pytorch.org/whl/cpu/torch_stable.html

v1.0.1

Conda

OSX

# conda
conda install pytorch==1.0.1 torchvision==0.2.2 -c pytorch

Linux and Windows

# CUDA 9.0
conda install pytorch==1.0.1 torchvision==0.2.2 cudatoolkit=9.0 -c pytorch

# CUDA 10.0
conda install pytorch==1.0.1 torchvision==0.2.2 cudatoolkit=10.0 -c pytorch

# CPU Only
conda install pytorch-cpu==1.0.1 torchvision-cpu==0.2.2 cpuonly -c pytorch

Wheel

OSX

pip install torch==1.0.1 torchvision==0.2.2

Linux and Windows

# CUDA 10.0
Download and install wheel from https://download.pytorch.org/whl/cu100/torch_stable.html

# CUDA 9.0
Download and install wheel from https://download.pytorch.org/whl/cu90/torch_stable.html

# CPU only
Download and install wheel from https://download.pytorch.org/whl/cpu/torch_stable.html

v1.0.0

Conda

OSX

# conda
conda install pytorch==1.0.0 torchvision==0.2.1 -c pytorch

Linux and Windows

# CUDA 10.0
conda install pytorch==1.0.0 torchvision==0.2.1 cuda100 -c pytorch

# CUDA 9.0
conda install pytorch==1.0.0 torchvision==0.2.1 cuda90 -c pytorch

# CUDA 8.0
conda install pytorch==1.0.0 torchvision==0.2.1 cuda80 -c pytorch

# CPU Only
conda install pytorch-cpu==1.0.0 torchvision-cpu==0.2.1 cpuonly -c pytorch

Wheel

OSX

pip install torch==1.0.0 torchvision==0.2.1

Linux and Windows

# CUDA 10.0
Download and install wheel from https://download.pytorch.org/whl/cu100/torch_stable.html

# CUDA 9.0
Download and install wheel from https://download.pytorch.org/whl/cu90/torch_stable.html

# CUDA 8.0
Download and install wheel from https://download.pytorch.org/whl/cu80/torch_stable.html

# CPU only
Download and install wheel from https://download.pytorch.org/whl/cpu/torch_stable.html

COMMANDS FOR VERSIONS < 1.0.0

Via conda

This should be used for most previous macOS version installs.

To install a previous version of PyTorch via Anaconda or Miniconda, replace “0.4.1” in the following commands with the desired version (i.e., “0.2.0”).

Installing with CUDA 9

conda install pytorch=0.4.1 cuda90 -c pytorch

or

conda install pytorch=0.4.1 cuda92 -c pytorch

Installing with CUDA 8

conda install pytorch=0.4.1 cuda80 -c pytorch

Installing with CUDA 7.5

conda install pytorch=0.4.1 cuda75 -c pytorch

Installing without CUDA

conda install pytorch=0.4.1 -c pytorch

From source

It is possible to checkout an older version of PyTorch and build it. You can list tags in PyTorch git repository with git tag and checkout a particular one (replace ‘0.1.9’ with the desired version) with

git checkout v0.1.9

Follow the install from source instructions in the README.md of the PyTorch checkout.

Via pip

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

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

Note: most pytorch versions are available only for specific CUDA versions. For example pytorch=1.0.1 is not available for CUDA 9.2

(Old) PyTorch Linux binaries compiled with CUDA 7.5

These predate the html page above and have to be manually installed by downloading the wheel file and pip install downloaded_file

Windows binaries

Mac and misc. binaries

For recent macOS binaries, use conda:

e.g.,

conda install pytorch=0.4.1 cuda90 -c pytorch conda install pytorch=0.4.1 cuda92 -c pytorch conda install pytorch=0.4.1 cuda80 -c pytorch conda install pytorch=0.4.1 -c pytorch # No CUDA

pytorch最近已经更新到了稳定版本,从Pytorch官网上可以看到有多种安装方式,比较常见的方法是通过pip和conda安装,当使用conda安装的时候,可能会遇到下载过慢的问题,下载的时候可能会遇到无尽的等待。这里推荐用清华源替代默认conda源的方法,可以解决下载过慢的问题。

添加清华源

    conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
    conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
    conda config --set show_channel_urls yes

另外为了保险起见,建议同时添加第三方conda源:

    conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/
    conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/msys2/
    conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/bioconda/
    conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/menpo/
    conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/

根据Python和CUDA选择对应的版本,然后官方给出提示可通过运行:

conda install pytorch torchvision cudatoolkit=9.0 -c pytorch
但是这里一定要注意,去掉-c pytorch,安装的时候才会默认从清华源下载相应的包,因此这里用命令行:

conda install pytorch torchvision cudatoolkit=9.0

 

可能遇到的问题

  • AttributeError: 'Conv2d' object has no attribute 'padding_mode'

Solution:PyTorch 版本问题,1.1.0 版会出现这个问题,回退到 0.4.0 版本即可。

复制
$ pip install -i https://pypi.tuna.tsinghua.edu.cn/simple --upgrade torch==0.4.0 torchvision==0.2.0

 

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

向阳+

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值