Python 如何使用 conda 或 pip 在 Anaconda 中安装 pytorch?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/49918479/
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 19:18:18  来源:igfitidea点击:

How to install pytorch in Anaconda with conda or pip?

pythonpippytorch

提问by Marisa

I am trying to install pytorch in Anaconda to work with Python 3.5 in Windows. Following the instructions in pytorch.orgI introduced the following code in Anaconda:

我正在尝试在 Anaconda 中安装 pytorch 以在 Windows 中使用 Python 3.5。按照pytorch.org 中的说明,我在 Anaconda 中引入了以下代码:

pip3 install torch torchvision 

But the following error came in:

但是出现了以下错误:

Command "python setup.py egg_info" failed with error code 1 in C:\Users\sluis\AppData\Local\Temp\pip-install-qmrvz7b9\torch\

By searching on the web I found out that it may be because of setuptoolsbeing out of date but I checked and have it updated. I also tried:

通过在网上搜索,我发现它可能是因为setuptools过时了,但我检查并更新了它。我也试过:

conda install -c peterjc123 pytorch cuda80

But the following error arise:

但是出现以下错误:

The following specifications were found to be in conflict:
  - pytorch
Use "conda info <package>" to see the dependencies for each package.

I also tried to load the pytorch's tar.bz2 file which I download in the following website:

我还尝试加载我在以下网站下载的 pytorch 的 tar.bz2 文件:

anaconda.org/peterjc123/pytorch/files

anaconda.org/peterjc123/pytorch/files

And then just do:

然后就这样做:

$ conda install filename.tar.bz2 

But I got the following error:

但我收到以下错误:

Error: HTTPError: 404 Client Error: None for url: file:///C|/Users/sluis/pytorch-0.3.1-py36_cuda80_cudnn6he774522_2.tar.bz2: file:///C|/Users/sluis/pytorch-0.3.1-py36_cuda80_cudnn6he774522_2.tar.bz2

I am quite new to this programming world so I don't really know how to dig more on the errors. Anyone knows how to get pytorch installed?

我对这个编程世界很陌生,所以我真的不知道如何挖掘更多的错误。有人知道如何安装pytorch吗?

Edit:As suggested in the comments I tried:

编辑:正如我尝试的评论中所建议的:

conda install pytorch torchivsion -c pytorch

And I got the following error:

我收到以下错误:

Error: Packages missing in current win-64 channels:
 - pytorch
 - torchvision

I did:

我做了:

anaconda search -t conda torchvision

And tried to install dericlk/torchvisionusing the following command:

并尝试dericlk/torchvision使用以下命令进行安装:

conda install -c derickl torchvision

But I am getting the same error:

但我收到同样的错误:

Error: Package missing in current win-64 channels:
  - torchvision

I couldn't find any torchvisionpackages for win-64.

我找不到任何torchvision适用于 win-64 的软件包。

conda listis giving me the following:

conda list给了我以下内容:

# packages in environment at C:\Users\aaaa\AppData\Local\Continuum\Anaconda3\envs\torchenv2:
#
mkl-include               2018.0.2                      1    anaconda
certifi                   2016.2.28                py35_0
cffi                      1.10.0                   py35_0
cmake                     3.6.3                    vc14_0  [vc14]
openmp                    2018.0.0                intel_8    intel
mkl                       2017.0.3                      0
numpy                     1.13.1                   py35_0
pip                       10.0.0                    <pip>
pip                       9.0.1                    py35_1
pycparser                 2.18                     py35_0
python                    3.5.4                         0
pyyaml                    3.12                     py35_0
setuptools                36.4.0                   py35_1
typing                    3.6.2                    py35_0
vc                        14                            0
vs2015_runtime            14.0.25420                    0
wheel                     0.29.0                   py35_0
wincertstore              0.2                      py35_0
zlib                      1.2.11                   vc14_0  [vc14]

=======

========

回答by archit522

The following worked for me. First install MKL:

以下对我有用。首先安装MKL

conda install -c anaconda mkl

After this, install pytorch and torchvision:

在此之后,安装 pytorch 和 torchvision:

conda install -c pytorch pytorch torchvision

回答by smart74

Go to the official PyTorch.organd follow the steps accordingly. enter image description here

转到官方PyTorch.org并按照相应步骤操作。 在此处输入图片说明

Select your preferences and you will see an appropriate command below on the page.

选择您的首选项,您将在页面下方看到相应的命令。

If you don't have GPU in the system, set CUDAas None

如果系统中没有 GPU,请将CUDA设置为None

Example command:

示例命令:

conda install pytorch-cpu torchvision-cpu -c pytorch

回答by Lakshmi Bhavani - Intel

Can you please try with below steps

你能试试下面的步骤吗

  1. conda create -n pytorch_env python=3.5
  2. source activate pytorch_env
  3. conda install -c soumith pytorch
  4. python

    > import torch

  1. conda create -n pytorch_env python=3.5
  2. source activate pytorch_env
  3. conda install -c soumith pytorch
  4. python

    > import torch

You can even find pytorchafter you execute command conda list.

您甚至可以pytorch在执行命令后找到conda list

回答by Shu Zhang

For linux, cuda9.0, python3.6:

对于 linux、cuda9.0、python3.6:

pip3 install http://download.pytorch.org/whl/cu90/torch-0.3.1-cp36-cp36m-linux_x86_64.whl

pip3 安装http://download.pytorch.org/whl/cu90/torch-0.3.1-cp36-cp36m-linux_x86_64.whl

pip3 install torchvision

pip3 安装火炬视觉

For other cuda/python version: check website: https://ptorch.com/news/145.html

对于其他 cuda/python 版本:查看网站:https: //ptorch.com/news/145.html

回答by Richardd

For me it worked doing this:

对我来说,它可以这样做:

Uninstall the previous version: go to C:\users\username\anaconda3 and run the anaconda-uninstall.exe

卸载以前的版本:转到 C:\users\username\anaconda3 并运行 anaconda-uninstall.exe

Install again anaconda

再次安装anaconda

then run the following commands on the anaconda pompt:

然后在 anaconda pompt 上运行以下命令:

conda create -n my_env python=2.7

conda create -n my_env python=2.7

conda activate my_env

conda activate my_env

start the gui app

启动gui应用程序

conda install -c peterjc123 pytorch

conda install -c peterjc123 pytorch

anaconda-navigator

anaconda-navigator

回答by Rachit Srivastava

Visit https://anaconda.org/pytorch/torchvisionand you will find the solution

访问https://anaconda.org/pytorch/torchvision,您将找到解决方案

conda install -c pytorch torchvision

回答by Ankit Sindhu

For windowspython3.6 and above without cuda

对于没有cuda 的windows python3.6 及更高版本

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

回答by Shreya

Try running:

尝试运行:

conda install -c pytorch pytorch

回答by rachana

try updating the base conda package with the following command,then you can try reistalling it.

尝试使用以下命令更新基础 conda 包,然后您可以尝试重新安装它。

  1. conda update --all
  2. conda update -n base conda
  1. 康达更新 --all
  2. conda update -n 基础 conda