PyTorch 1.12在Mac蒙特雷上的应用

omvjsjqw  于 2022-11-09  发布在  Mac
关注(0)|答案(2)|浏览(233)

我无法在带有M1芯片的macOS 12.6 Monterey上使用PyTorch 1.12.1。
尝试从Python 3.8、3.9和3.10安装和运行,结果相同。
我认为PyTorch在我将macOS更新到Monterey之前就已经在工作了。Rust绑定,tch-rs仍然在工作。
这是我的安装和错误消息时,我得到尝试运行。

安装

brew install libtorch

python3.9 -m venv venv39

source venv39/bin/activate

pip3 install torch torchvision torchaudio

错误消息

python
Python 3.9.14 (main, Sep  6 2022, 23:16:16)
[Clang 13.1.6 (clang-1316.0.21.2.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import torch
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "~/Documents/install/Modern_Computer_Vision/venv39/lib/python3.9/site-packages/torch/__init__.py", line 202, in <module>
    from torch._C import *  # noqa: F403
ImportError: dlopen(~/Documents/install/Modern_Computer_Vision/venv39/lib/python3.9/site-packages/torch/_C.cpython-39-darwin.so, 0x0002): Symbol not found: (__ZN4c10d11debug_levelEv)
  Referenced from: '@/Documents/install/Modern_Computer_Vision/venv39/lib/python3.9/site-packages/torch/lib/libtorch_python.dylib'
  Expected in: '/opt/homebrew/Cellar/libtorch/1.12.1/lib/libtorch_cpu.dylib'

已尝试使用Miniconda

我得到了几乎相同的结果。

conda create -n conda39 python=3.9 -y
conda activate conda39
conda install pytorch torchvision torchaudio -c pytorch

❯ python
Python 3.9.12 (main, Apr  5 2022, 01:52:34)
[Clang 12.0.0 ] :: Anaconda, Inc. on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import torch
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/sami/miniconda3/lib/python3.9/site-packages/torch/__init__.py", line 202, in <module>
    from torch._C import *  # noqa: F403
ImportError: dlopen(/Users/sami/miniconda3/lib/python3.9/site-packages/torch/_C.cpython-39-darwin.so, 0x0002): Symbol not found: (__ZN4c10d11debug_levelEv)
  Referenced from: '/Users/sami/miniconda3/lib/python3.9/site-packages/torch/lib/libtorch_python.dylib'
  Expected in: '/opt/homebrew/Cellar/libtorch/1.12.1/lib/libtorch_cpu.dylib'
vhmi4jdf

vhmi4jdf1#

我建议 * 不要 * 在你自己的项目中接触你的系统python安装,相反,推荐的方法是使用conda(参见here)。原因是每个conda环境都封装了一个完整的单独的python安装,它不会干扰(也不会被干扰)任何其他程序。这对于像pytorch正在使用的C/C++库来说尤其重要。

ckx4rj1h

ckx4rj1h2#

我在尝试安装PyTorch 1.13时遇到了类似的问题。
PyTorch安装指令不起作用,但这是由于Brew和Miniconda之间的冲突。当我卸载Miniconda时,稳定和夜间PIP安装都起作用了。

virtualenv -p /opt/homebrew/Cellar/python@3.9/3.9.14/bin/python3.9 pt113
source pt113/bin/activate

pip3 install torch torchvision torchaudio

pip3 install --pre torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/nightly/cpu

相关问题