如何在Python2.7中安装PyTorch?

4

我正在虚拟环境中使用Python2.7。我尝试在Python2.7中安装PyTorch,但是出现了以下错误:

UnsatisfiableError: The following specifications were found
to be incompatible with the existing python installation in your environment:

  - pytorch-cpu -> python[version='3.5.*|3.6.*']
  - pytorch-cpu -> python[version='>=3.5,<3.6.0a0|>=3.6,<3.7.0a0|>=3.7,<3.8.0a0']

If python is on the left-most side of the chain, that's the version you've asked for.
When python appears to the right, that indicates that the thing on the left is somehow
not available for the python version you are constrained to.  Your current python version
is (python=2.7).  Note that conda will not change your python version to a different minor version
unless you explicitly specify that.

The following specifications were found to be incompatible with each other:



Package wheel conflicts for:
python=2.7 -> pip -> wheel
pytorch-cpu -> python[version='>=3.6,<3.7.0a0'] -> pip -> wheel
Package vc conflicts for:
python=2.7 -> sqlite[version='>=3.27.2,<4.0a0'] -> vc[version='14.*|>=14,<15.0a0|>=14.1,<15.0a0']
python=2.7 -> vc[version='9.*|>=9,<10.0a0']
pytorch-cpu -> numpy[version='>=1.11'] -> vc[version='14|14.*|>=14,<15.0a0']
pytorch-cpu -> vc[version='>=14.1,<15.0a0']
Package cffi conflicts for:
pytorch-cpu -> cffi
pytorch-cpu -> python[version='>=3.6,<3.7.0a0'] -> pip -> requests -> urllib3[version='>=1.21.1,<1.25'] -> cryptography[version='>=1.3.4'] -> cffi[version='>=1.7']
python=2.7 -> pip -> requests -> urllib3[version='>=1.21.1,<1.25'] -> cryptography[version='>=1.3.4'] -> cffi[version='>=1.7']
Package pip conflicts for:
python=2.7 -> pip
pytorch-cpu -> python[version='>=3.6,<3.7.0a0'] -> pip
Package setuptools conflicts for:
python=2.7 -> pip -> setuptools
pytorch-cpu -> python[version='>=3.6,<3.7.0a0'] -> pip -> setuptools
Package msgpack-python conflicts for:
python=2.7 -> pip -> cachecontrol -> msgpack-python
pytorch-cpu -> python[version='>=3.6,<3.7.0a0'] -> pip -> cachecontrol -> msgpack-python

我尝试使用conda install pytorch-cpu -c pytorch以及链接(https://pytorch.org/get-started/locally/)安装,但是没有成功。那么我应该如何在Python版本2.7中安装torch?我想安装pytorch cpu版本。
请帮忙:)

1
无论是针对PyTorch还是机器学习,您最好在虚拟环境中安装Python 3。 - anirudh
4个回答

2

1

1

首先安装conda和python2.7:
conda install pytorch torchvision torchaudio cpuonly -c pytorch

然后激活环境:
conda activate python2

接着安装pytorch:
conda install pytorch torchvision torchaudio cpuonly -c pytorch

确认是否安装成功:

python    
import torch
print(torch._ _version_ _)

1
似乎pytorch试图安装一些需要python >= 3.6版本的包。
Package wheel conflicts for:
python=2.7 -> pip -> wheel
pytorch-cpu -> python[version='>=3.6,<3.7.0a0'] -> pip -> wheel

您需要在命令中指定要安装PyTorch的Python版本。


那么,您的意思是我应该为Python2.7指定Pytorch版本? - mimi
1
你使用的是哪个操作系统?请注意,PyTorch不支持在Windows上使用Python 2.7。 - Ishinomori
我使用Windows。天哪!我不能在Windows上使用Python2.7中的Torch吗?:( - mimi

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接