gpt4 book ai didi

python - 导入 PyTorch 时出错 - Python

转载 作者:行者123 更新时间:2023-12-01 02:41:23 25 4
gpt4 key购买 nike

我尝试在终端中使用以下命令安装 PyTorch:

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)

编辑二

以下命令:

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

最佳答案

关于http://pytorch.org/与:

  • 操作系统:OSX
  • 包管理器:pip
  • Python:2.7
  • CUDA:无

我有:

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,这意味着您应该选择 Package manager: conda 而不是

在这种情况下,您应该删除使用 pip 安装的软件包:

pip uninstall torch

并使用 anaconda 命令代替:

  • 操作系统:OSX
  • 包管理器:conda
  • Python:2.7
  • CUDA:无

运行命令:

conda install pytorch torchvision -c soumith

关于python - 导入 PyTorch 时出错 - Python,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45673949/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com