Mac:使用pip3安装pytorch后import报错:Reason: image not found

  • MacOS Mojava 10.14.5
  • python 3.6.2
  • pip 19.1.1
  • torch-1.1.0
  • torchvision-0.3.0

使用如下命令安装pytorch:

pip3 install torch torchvision

安装成功后导入模块失败:

>>> import torch
Traceback (most recent call last):
  File "", line 1, in 
  File "/Users/chao/.pyenv/versions/3.6.2/lib/python3.6/site-packages/torch/__init__.py", line 79, in 
    from torch._C import *
ImportError: dlopen(/Users/chao/.pyenv/versions/3.6.2/lib/python3.6/site-packages/torch/_C.cpython-36m-darwin.so, 9): Library not loaded: /usr/local/opt/libomp/lib/libomp.dylib
  Referenced from: /Users/chao/.pyenv/versions/3.6.2/lib/python3.6/site-packages/torch/lib/libshm.dylib
  Reason: image not found
  • 解决方案:首先确保你的Mac已经安装过homebrew,然后一条命令解决问题:
brew install libomp

你可能感兴趣的:(L_Python)