2017-08-14 166 views
1

我曾尝试在终端使用下面的命令来安装PyTorch:错误导入PyTorch - Python的

pip install http://download.pytorch.org/whl/torch-0.2.0.post1-cp27-none-macosx_10_7_x86_64.whl 

然后我在Python运行下面的代码:

import torch 
torch.__file__ 

,并出现以下错误:

File "/Users/brian/anaconda/lib/python2.7/site-packages/torch/__init__.py", line 48, in <module> 
import torch._dl as _dl_flags 

AttributeError: 'module' object has no attribute '_dl' 

我试图研究这个问题,但找不到明确的答案。任何帮助,将不胜感激。

编辑: 这些是从尝试使用下面的命令来重新安装PyTorch结果:

pip install http://download.pytorch.org/whl/torch-0.2.0.post1-cp27-none-macosx_10_7_x86_64.whl 
pip install torchvision 

结果:

Requirement already satisfied: pyyaml in ./anaconda/lib/python2.7/site-packages (from torch==0.2.0.post1) 
Requirement already satisfied: numpy in ./anaconda/lib/python2.7/site-packages (from torch==0.2.0.post1) 


Requirement already satisfied: torchvision in ./anaconda/lib/python2.7/site-packages 
Requirement already satisfied: pillow in ./anaconda/lib/python2.7/site-packages (from torchvision) 
Requirement already satisfied: torch in ./anaconda/lib/python2.7/site-packages (from torchvision) 
Requirement already satisfied: numpy in ./anaconda/lib/python2.7/site-packages (from torchvision) 
Requirement already satisfied: six in ./anaconda/lib/python2.7/site-packages (from torchvision) 
Requirement already satisfied: olefile in ./anaconda/lib/python2.7/site-packages (from pillow->torchvision) 
Requirement already satisfied: pyyaml in ./anaconda/lib/python2.7/site-packages (from torch->torchvision) 

EDIT II

下面的命令:

conda install pytorch torchvision cuda80 -c soumith 

产生这样的结果:

Fetching package metadata ........... 

PackageNotFoundError: Packages missing in current channels: 

    - cuda80 

We have searched for the packages in the following channels: 

    - https://conda.anaconda.org/soumith/osx-64 
    - https://conda.anaconda.org/soumith/noarch 
    - https://repo.continuum.io/pkgs/free/osx-64 
    - https://repo.continuum.io/pkgs/free/noarch 
    - https://repo.continuum.io/pkgs/r/osx-64 
    - https://repo.continuum.io/pkgs/r/noarch 
    - https://repo.continuum.io/pkgs/pro/osx-64 
    - https://repo.continuum.io/pkgs/pro/noarch 
+0

似乎安装没有做好,或者你错过一些包。你使用的是哪个Mac OS?我几天前安装了它,但我没有遇到同样的问题。可以肯定,你是否运行这些命令: pip install http://download.pytorch.org/whl/torch-0.2.0.post1-cp27-none-macosx_10_7_x86_64.whl pip install torchvision 对不对? –

+0

我已经添加了终端响应,在问题中再次这样做。你碰巧知道终端命令卸载pytorch,我可以试试吗? –

+0

@BrianPeach看起来你的Mac上安装了anaconda,请尝试使用下列选项:'conda install pytorch torchvision cuda80 -c soumith' –

回答

2

http://pytorch.org/有了:

  • OS:OSX
  • 软件包管理器:PIP
  • 的Python:2.7
  • CUDA:无

我走了T:

pip install http://download.pytorch.org/whl/torch-0.2.0.post1-cp27-none-macosx_10_7_x86_64.whl 
pip install torchvision 
# OSX Binaries dont support CUDA, install from source if CUDA is needed 
  • 您一定要选择正确的选择吗?
  • 你试过第二个命令,pip install torchvision

编辑

似乎在你的日志,你必须安装在您的Mac anaconda,这意味着你应该有选择软件包管理器:conda而不是pip

在这种情况下,你应该删除使用PIP安装包:

pip uninstall torch 

而且使用蟒蛇,而不是使用命令:

  • OS:OSX
  • 软件包管理器:畅达
  • Python:2.7
  • CUDA:无

运行命令:

conda install pytorch torchvision -c soumith 
+0

我在问题中添加了终端响应以再次执行此操作。你碰巧知道终端命令卸载pytorch,我可以试试吗? –

+1

已经解决了,谢谢你的帮助:) –

+0

@BrianPeach我很高兴,我相信你不会是唯一一个有这个问题的人。下次请花时间检查您的安装选项;) –

0

使用泊坞窗是一个很好的解决方案有一个可重复的环境中到处去设置环境的问题。您可以从here安装码头。您可以使用Dockerfile

如果你需要在没有使用docker的情况下安装pytorch,Dockerfile在操作系统和基本Docker镜像相同的情况下提供了一个很好的一步一步安装方式。

您也可以尝试使用datmo来设置环境和跟踪机器学习项目,以使模型具有可再现性。

0

我遇到了同样的问题,可能是因为numpy的版本,我通过升级numpy包来解决这个问题。

pip install -U numpy 

然后事情似乎进展顺利~~