无法导入火炬mac

时间:2018-05-19 13:20:40

标签: python macos pytorch torch

我试图导入火炬并且我遇到了下一个问题:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/torch/__init__.py", line 66, in <module>
    import torch._dl as _dl_flags
ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/torch/_dl.so, 2): no suitable image found.  Did find:
    /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/torch/_dl.so: mach-o, but wrong architecture
    /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/torch/_dl.so: mach-o, but wrong architecture

有人知道我该如何解决这个问题? 感谢:)

2 个答案:

答案 0 :(得分:2)

尝试这样:

mkdir test_torch
cd test_torch
python3 -m venv .venv
source .venv/bin/activate
pip install torch torchvision
python3

>>> import torch

适合我。 MacOS 10.13.4,Python 3.6.4

或者那样:

mkdir test_torch
cd test_torch
virtualenv .venv
source .venv/bin/activate
pip install --upgrade pip
pip install torch torchvision
python2

>>> import torch

适合我。 MacOS 10.13.4,Python 2.7.10

如果您不需要使用torch,那么您只能安装torchvision

pip install --no-deps torchvision

答案 1 :(得分:0)

尝试

brew install libomp

应该解决问题