PyTorch 1.12.1 on Mac Monterey with M1

I cannot use PyTorch 1.12.1 on macOS 12.6 Monterey with M1 chip.

Tried to install and run from Python 3.8, 3.9 and 3.10 with the same result.

I think that PyTorch was working before I updated macOS to Monterey. And the Rust bindings, tch-rs are still working.

Here is my install and the error messages I get when trying to run.

Install

brew install libtorch

python3.9 -m venv venv39

source venv39/bin/activate

pip3 install torch torchvision torchaudio

Error message

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 attempt

Miniconda gave almost the same result as pip:

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
>>> import torch
  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)

Hi @Sami_Badawi,

When you used pip to install did you do this within a fresh virtual env? I’ve had similar errors before when I’ve installed torch into the base pip environment and not my fresh virtual environment.

Hi @AlphaBetaGamma96,

I did it in brand new virtual environments. This was the commands I used.

python3.9 -m venv venv39
source venv39/bin/activate
pip3 install torch torchvision torchaudio
python

import torch

I had similar problem when trying to install PyTorch 1.13.

The PyTorch install instruction was not working, but it was due to a conflict between brew and Miniconda. When I uninstalled Miniconda both stable and nightly pip install worked.

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