如何解决MacOs上导入torch错误?

问题描述 投票:0回答:1
ImportError                               Traceback (most recent call last)
Input In [1], in <cell line: 1>()
----> 1 import torch

File /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/torch/__init__.py:202, in <module>
    200     if USE_GLOBAL_DEPS:
    201         _load_global_deps()
--> 202     from torch._C import *  # noqa: F403
    204 # Appease the type checker; ordinarily this binding is inserted by the
    205 # torch._C module initialization code in C
    206 if TYPE_CHECKING:

ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/torch/_C.cpython-39-darwin.so, 2): Library not loaded: @loader_path/../.dylibs/libomp.dylib
  Referenced from: /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/torch/lib/libtorch_cpu.dylib
  Reason: no suitable image found.  Did find:
    /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/torch/lib/../.dylibs/libomp.dylib: cannot load 'libomp.dylib' (load command 0x80000034 is unknown)
    /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/torch/lib/../.dylibs/libomp.dylib: cannot load 'libomp.dylib' (load command 0x80000034 is unknown)

这是我在 MacO 上使用 Jupyter Notebook 时遇到的错误。我已经使用命令“pip3 install torch torchvision torchaudio”安装了 Pytorch,它显示它已成功安装。我尝试安装Anaconda,但是Anaconda安装失败,所以,使用pip3安装了torch。

可能是什么原因? 我该如何解决这个问题?

我正在尝试并期待解决此错误。

python macos jupyter-notebook pytorch
1个回答
0
投票

检查你的解释器(你目前使用的Python版本)。

要检查 Jupyter Notebook 中的 Python 版本,请首先使用“ from platform import python_version ”导入 python_version 函数。然后调用函数 python_version(),该函数返回一个字符串,其中包含 Jupyter 笔记本中运行的版本号,例如 (“3.7.11”) <- example.

然后检查您使用的python版本是否与本次操作时给出的版本相同。

© www.soinside.com 2019 - 2024. All rights reserved.