I installed pytorch successfully on my Mac (Sierra 10.12.6), using pip install --user torch==1.0.0. However, when I try to import torch from inside python (2.7.10), I get the following error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/username/Library/Python/2.7/lib/python/site-packages/torch/__init__.py", line 84, in <module>
from torch._C import *
ImportError: dlopen(/Users/username/Library/Python/2.7/lib/python/site-packages/torch/_C.so, 9): Library not loaded: @rpath/libc++.1.dylib
Referenced from: /Users/username/Library/Python/2.7/lib/python/site-packages/torch/_C.so
Reason: image not found
I know of at least one other user who has had exactly the same problem, but on the Mojave os, for the same versions of python and torch. Previously, I was able to run torch 0.4.1 without incident, this problem is only post-upgrade. I am able to run torch 1.0.0 with python 3.6.5 (within a virtualenv) fine.
Thanks! I installed torch globally. I fixed the issue with
sudo install_name_tool -add_rpath /usr/lib /Library/Python/2.7/lib/python/site-packages/torch/_C.so
In case, if you used brew installed python, the command looks like: sudo install_name_tool -add_rpath /usr/lib /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/torch/_C.cpython-38-darwin.so
ImportError: dlopen(/Users/tylcole/.virtualenvs/stanza/lib/python3.8/site-packages/torch/_C.cpython-38-darwin.so, 9): Library not loaded: @rpath/libc++.1.dylib
Referenced from: /Users/tylcole/.virtualenvs/stanza/lib/python3.8/site-packages/torch/_C.cpython-38-darwin.so
Reason: image not found
And I tried
install_name_tool -add_rpath /usr/lib /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/torch/_C.cpython-38-darwin.so
But the error that I get is:
error: /Library/Developer/CommandLineTools/usr/bin/install_name_tool: for: /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/torch/_C.cpython-38-darwin.so (for architecture x86_64) option “-add_rpath /usr/lib” would duplicate path, file already has LC_RPATH for: /usr/lib
I am just trying to use Python for one part in a project and I am getting stuck on this. I’m not too familiar with how it stores files and deals with virtual environments differently.