Python 如何在 Windows 中安装 pytorch?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/47754749/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 18:21:08  来源:igfitidea点击:

How to install pytorch in windows?

pythonwindowsanacondapytorchconda

提问by Pratik Sapkota

I am trying to install pytorch on windows and there is one which is available for it but shows an error.

我正在尝试在 Windows 上安装 pytorch,并且有一个可用但显示错误。

conda install -c peterjc123 pytorch=0.1.12

回答by suimizu

Warning: Unless you have a very specific reason not to, just follow the official installation instructions from https://pytorch.org. They are far more likely to be accurate and up-to-date.

警告:除非您有非常具体的理由不这样做,否则只需按照https://pytorch.org的官方安装说明进行操作即可。它们更有可能是准确和最新的。



Here is how to install the PyTorch package from the official channel, on Windows using Anaconda, as of the time of writing this comment (31/03/2020):

以下是截至撰写此评论时 (31/03/2020) 在 Windows 上使用 Anaconda 从官方渠道安装 PyTorch 包的方法:

PyTorch without CUDA:

没有 CUDA 的 PyTorch:

conda install pytorch torchvision cpuonly -c pytorch

PyTorch with CUDA 10.1:

带有 CUDA 10.1 的 PyTorch:

conda install pytorch torchvision cudatoolkit=10.1 -c pytorch

回答by DK250

go to the official website: http://pytorch.org/

去官网:http: //pytorch.org/

  1. Select Windows as your operating system
  2. Select your Package Manager such as pip or conda
  3. Select you python version
  4. Select CUDA or choose none You will get the command that will install pytorch on your system based on your selection.
  1. 选择 Windows 作为您的操作系统
  2. 选择您的包管理器,例如 pip 或 conda
  3. 选择你的python版本
  4. 选择 CUDA 或选择 none 您将获得将根据您的选择在您的系统上安装 pytorch 的命令。

For example, if you choose Windows, pip, python 3.6and nonein the listed steps, you will get the following commands:

例如,如果您在列出的步骤中选择Windows、pip、python 3.6none,您将获得以下命令:

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

回答by x0s

Actual answer:

实际答案



Best way is to check on the official websitefor up-to-date options. Here are the ones working as of 2020-03:

最好的方法是在官方网站上查看最新选项。以下是截至 2020-03 年的工作:

# for windows 10, CUDA 10.1
conda install pytorch torchvision cudatoolkit=10.1 -c pytorch

#for windows 10, CUDA 9
conda install pytorch torchvision cudatoolkit=9.2 -c pytorch -c defaults -c numba/label/dev 

Previous answer(out-of-date)

以前的答案(过时)



It seems that the author (peterjc123) released 2 days ago conda packages to install PyTorch 0.3.0 on windows. Here is a copy:

似乎作者(peterjc123)在 2 天前发布了 conda 包来在 Windows 上安装 PyTorch 0.3.0。这是一个副本:

# for Windows 10 and Windows Server 2016, CUDA 8
conda install -c peterjc123 pytorch cuda80

# for Windows 10 and Windows Server 2016, CUDA 9
conda install -c peterjc123 pytorch cuda90

# for Windows 7/8/8.1 and Windows Server 2008/2012, CUDA 8
conda install -c peterjc123 pytorch_legacy cuda80

source: https://github.com/pytorch/pytorch/issues/494#issuecomment-350527200

来源:https: //github.com/pytorch/pytorch/issues/494#issuecomment-350527200

回答by Navin Dalal

If you are trying to install on windows 10 and you are not having the anaconda installation than the best options are below:

如果您尝试在 Windows 10 上安装并且您没有安装 anaconda,那么最好的选择如下:

Python 2.7

蟒蛇 2.7

pip install https://download.pytorch.org/whl/cpu/torch-1.0.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

如果上面的命令不起作用,那么你有python 2.7 UCS2,使用这个命令

pip install https://download.pytorch.org/whl/cpu/torch-1.0.1-cp27-cp27m-linux_x86_64.whl

Python 3.5

蟒蛇 3.5

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

Python 3.6

蟒蛇 3.6

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

Python 3.7

蟒蛇 3.7

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

回答by Sheraz

Update June 2019: pytorch has a dedicated conda channel now and can be installed easily with anaconda. The command generated at pytorch will require dependencies before it can be executed successfully. For example I chose stable pytorch 1.1 build with python 3.6 and Cuda 10.0. The command generated by pytorch page was as follows:

2019 年 6 月更新:pytorch 现在有一个专用的 conda 频道,可以使用 anaconda 轻松安装。在 pytorch 生成的命令需要依赖才能成功执行。例如,我选择了带有 python 3.6 和 Cuda 10.0 的稳定 pytorch 1.1 版本。pytorch页面生成的命令如下:

conda install pytorch torchvision cudatoolkit=10.0 -c pytorch

conda 安装 pytorch torchvision cudatoolkit=10.0 -c pytorch

But it will not work if you have created a new conda environment like me. The step by step process for setting up pytorch is as follows:

但是如果你像我一样创建了一个新的 conda 环境,它就行不通了。设置pytorch的分步过程如下:

  • First install the cudatoolkit as follows:
  • 首先安装cudatoolkit,如下所示:

conda install -c anaconda cudatoolkit=10.0

conda install -c anaconda cudatoolkit=10.0

  • Then install the mkl_fft as follows:
  • 然后安装 mkl_fft 如下:

conda install -c anaconda mkl_fft

conda install -c anaconda mkl_fft

  • Assuming you will face no more dependency issues. Use the following command to setup pytorch:
  • 假设您将不再面临依赖问题。使用以下命令设置 pytorch:

conda install -c pytorch pytorch

conda install -c pytorch pytorch

This worked for me. But I had setup my new conda environment with scikit-learn and jupyter notebook before starting the pytorch setup. So if any dependency problem arise, it would be a good idea to install both scikit-learn and jupyter notebook as well.

这对我有用。但是在开始 pytorch 设置之前,我已经使用 scikit-learn 和 jupyter notebook 设置了我的新 conda 环境。因此,如果出现任何依赖问题,最好同时安装 scikit-learn 和 jupyter notebook。

回答by prosti

The trick is to go to the PyTorch websiteand select the things you need:

诀窍是去 PyTorch网站并选择你需要的东西:

enter image description here

在此处输入图片说明

回答by Shreya

Try running:

尝试运行:

conda install -c pytorch pytorch

The command will update/install: conda, cudatoolkit, pytorch.

该命令将更新/安装:conda、cudatoolkit、pytorch。

回答by pratiksha

pip install torch==1.5.0+cpu torchvision==0.6.0+cpu -f https://download.pytorch.org/whl/torch_stable.html

pip install torch==1.5.0+cpu torchvision==0.6.0+cpu -f https://download.pytorch.org/whl/torch_stable.html

回答by Sergey Batsura

Try this

尝试这个

  1. cd C:\Program files\Anaconda3\condabin
  2. conda install pytorch-cpu torchvision-cpu -c pytorch
  1. cd C:\Program files\Anaconda3\condabin
  2. conda 安装 pytorch-cpu torchvision-cpu -c pytorch

https://pytorch.org/get-started/locally/#anaconda

https://pytorch.org/get-started/locally/#anaconda

回答by Raj

for python 3.7 which is the latest till date

对于最新的python 3.7

for pytorch on cpu

用于 CPU 上的 pytorch

pip install https://download.pytorch.org/whl/cpu/torch-1.0.1-cp37-cp37m-win_amd64.whl

pip install https://download.pytorch.org/whl/cpu/torch-1.0.1-cp37-cp37m-win_amd64.whl

pip install torchvision

pip install torchvision