Mac Mini M2 Pro: import torch error, Library not loaded: @rpath/libffi.8.dylib

Hi Friends,

I just got my Mac Mini with M2 Pro Chip today, and so excited to install and run pytorch on it. I followed the instruction Accelerated PyTorch training on Mac - Metal - Apple Developer

curl -O
conda create -n torch
conda activate torch
conda install pytorch torchvision torchaudio -c pytorch-nightly

without any error.

However when I actually import the package, I saw below error. Sincerely appreciate your advice about how to solve it or let me know it is not solvable … (I tried hard to google search it, yet no luck :frowning: )

(torch) Evas-Mac-mini:Projects evah$ python
Python 3.11.3 (main, Apr 19 2023, 18:49:55) [Clang 14.0.6 ] 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/evah/miniconda3/envs/torch/lib/python3.11/site-packages/torch/", line 17, in <module>
    import ctypes
  File "/Users/evah/miniconda3/envs/torch/lib/python3.11/ctypes/", line 8, in <module>
    from _ctypes import Union, Structure, Array
ImportError: dlopen(/Users/evah/miniconda3/envs/torch/lib/python3.11/lib-dynload/, 0x0002): Library not loaded: @rpath/libffi.8.dylib
  Referenced from: <984D5B9C-4A47-3C59-BA2F-19CA5FA76707> /Users/evah/miniconda3/envs/torch/lib/python3.11/lib-dynload/
  Reason: tried: '/Users/evah/miniconda3/envs/torch/lib/python3.11/lib-dynload/../../libffi.8.dylib' (no such file), '/Users/evah/miniconda3/envs/torch/lib/python3.11/lib-dynload/../../libffi.8.dylib' (no such file), '/Users/evah/miniconda3/envs/torch/bin/../lib/libffi.8.dylib' (no such file), '/Users/evah/miniconda3/envs/torch/bin/../lib/libffi.8.dylib' (no such file), '/usr/local/lib/libffi.8.dylib' (no such file), '/usr/lib/libffi.8.dylib' (no such file, not in dyld cache)

I am checking out this old thread dyld: Library not loaded: /usr/local/opt/libffi/lib/libffi.6.dylib · Issue #7 · platformio/platform-lattice_ice40 · GitHub, trying out things they suggest to see if the problem could be solved (not yet)