PyTorch 1.12.1 on Mac Monterey with M1

Sami_Badawi: <p>I cannot use PyTorch 1.12.1 on macOS 12.6 Monterey with M1 chip.</p>
<p>Tried to install and run from Python 3.8, 3.9 and 3.10 with the same result.</p>
<p>I think that PyTorch was working before I updated macOS to Monterey. And the Rust bindings, tch-rs are still working.</p>
<p>Here is my install and the error messages I get when trying to run.</p>
<h2>
<a name="install-1" class="anchor" href="#install-1"></a>Install</h2>
<pre><code class="lang-auto">brew install libtorch

python3.9 -m venv venv39

source venv39/bin/activate

pip3 install torch torchvision torchaudio
</code></pre>
<h2>
<a name="error-message-2" class="anchor" href="#error-message-2"></a>Error message</h2>
<pre><code class="lang-auto">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.
&gt;&gt;&gt; import torch
Traceback (most recent call last):
  File "&lt;stdin&gt;", line 1, in &lt;module&gt;
  File "~/Documents/install/Modern_Computer_Vision/venv39/lib/python3.9/site-packages/torch/__init__.py", line 202, in &lt;module&gt;
    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'
</code></pre>
<h2>
<a name="miniconda-attempt-3" class="anchor" href="#miniconda-attempt-3"></a>Miniconda attempt</h2>
<p>Miniconda gave almost the same result as pip:</p>
<pre><code class="lang-auto">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
&gt;&gt;&gt; import torch
  File "/Users/sami/miniconda3/lib/python3.9/site-packages/torch/__init__.py", line 202, in &lt;module&gt;
    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)
</code></pre>

AlphaBetaGamma96: <p>Hi <a class="mention" href="/u/sami_badawi">@Sami_Badawi</a>,</p>
<p>When you used <code>pip</code> 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.</p>

Sami_Badawi: <p>Hi <a class="mention" href="/u/alphabetagamma96">@AlphaBetaGamma96</a>,</p>
<p>I did it in brand new virtual environments. This was the commands I used.</p>
<pre><code class="lang-bash">python3.9 -m venv venv39
source venv39/bin/activate
pip3 install torch torchvision torchaudio
python

import torch
</code></pre>

Sami_Badawi: <p>I had similar problem when trying to install PyTorch 1.13.</p>
<p>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.</p>
<pre><code class="lang-auto">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
</code></pre>