Library (dylib) not loaded - image not found - Python IDE

reason: image not found
reason: image not found abort trap: 6
library not loaded: /usr/local/opt/libomp/lib/libomp dylib
dyld library not loaded libxed dylib
dlopen image not found mac
dyld: library not loaded mojave
dyld: library not loaded: @rpath macos
library not loaded opt/cisco anyconnect lib libboost_system dylib

Basically I'm trying to run some Python code from savReaderWriter module in order to create a .sav file ready to open in IBM SPSS. As a macOS user I needed to run these two lines in the terminal first for the module to work:

echo 'export DYLD_LIBRARY_PATH=/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/savReaderWriter/spssio/macos'  >> ~/.bash_profile
echo 'export LC_ALL=en_US.UTF-8'  >> ~/.bash_profile

Below you can see a piece of code I'm trying to run in Python:

import savReaderWriter

savFileName = "someFile.sav"
records = [['Test1', 1, 1], ['Test2', 2, 1]]
varNames = ['var1', 'v2', 'v3']
varTypes = {'var1': 5, 'v2': 0, 'v3': 0}
with savReaderWriter.SavWriter(savFileName, varNames, varTypes, ioUtf8=True) as writer:
    for record in records:
        writer.writerow(record)

My problem is that while running the code in Python through terminal.app works like a charm and a new .sav file appears, trying to execute the very same code in an IDE (tried PyCharm and Spyder) gives me an error:

Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/IPython/core/interactiveshell.py", line 2847, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-2-94007b092d47>", line 7, in <module>
    with savReaderWriter.SavWriter(savFileName, varNames, varTypes, ioUtf8=True) as writer:
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/savReaderWriter/savWriter.py", line 198, in __init__
    super(Header, self).__init__(savFileName, ioUtf8, ioLocale)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/savReaderWriter/generic.py", line 29, in __init__
    self.spssio = self.loadLibrary()
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/savReaderWriter/generic.py", line 117, in loadLibrary
    spssio = self._loadLibs("macos")
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/savReaderWriter/generic.py", line 89, in _loadLibs
    return [load(os.path.join(path, lib)) for lib in libs][-1]
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/savReaderWriter/generic.py", line 89, in <listcomp>
    return [load(os.path.join(path, lib)) for lib in libs][-1]
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/ctypes/__init__.py", line 348, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: dlopen(/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/savReaderWriter/spssio/macos/libicuuc48.1.dylib, 6): Library not loaded: @executable_path/../lib/libicudata48.1.dylib
  Referenced from: /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/savReaderWriter/spssio/macos/libicuuc48.1.dylib
  Reason: image not found

The module author was unable to help me on this matter, therefore I would be very glad for any suggestions from this community.

EDIT (added sys.path):

From terminal:

 ['',
 '/Library/Frameworks/Python.framework/Versions/3.6/lib/python36.zip',
 '/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6',
 '/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/lib-dynload',
 '/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages',
 '/Users/mg/mne-python']

From IDE:

['/Applications/PyCharm.app/Contents/helpers/pydev',
 '/Users/mg/Documents/Python/Projects/MD',
 '/Applications/PyCharm.app/Contents/helpers/pydev',
 '/Library/Frameworks/Python.framework/Versions/3.6/lib/python36.zip',
 '/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6',
 '/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/lib-dynload',
 '/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages',
 '/Users/mg/mne-python',
 '/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/IPython/extensions',
 '/Users/mg/Documents/Python/Projects/MD']

Regards,

MG

Found the solution!

Basically I needed to create symbolic links to every dylib that appeared in the error, examples below:

sudo ln -s /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/savReaderWriter/spssio/macos/libicudata48.1.dylib /usr/local/lib/libicudata48.1.dylib
sudo ln -s /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/savReaderWriter/spssio/macos/libicui18n48.1.dylib /usr/local/lib/libicui18n48.1.dylib
sudo ln -s /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/savReaderWriter/spssio/macos/libspssdio.dylib /usr/local/lib/libspssdio.dylib
sudo ln -s /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/savReaderWriter/spssio/macos/libzlib123spss.dylib /usr/local/lib/libzlib123spss.dylib

So theoretically speaking:

sudo ln -s /path/to/original /path/to/symbolic/link

Regards,

MG

I can't import PyTorch, libomp.dylib can't be loaded. · Issue #20030 , It can't link dynamic library libomp.dylib To Reproduce Steps to reproduce /​python3.7/site-packages/torch/lib/libshm.dylib Reason: image not found you installed PyTorch ( conda , pip , source): pipenv; Python version: 3.7.1 it went through but other applications did not work anymore (Spyder IDE) ; at  @abmirayo From what I know, Homebrew installs things that Apple finds excessive and does not need in every computer, so it is not included in the normal OSX. Homebrew basically has the random files you might need for example the Flac file.

I'll add an answer to this question just to make it more generalizable. Would have preferred a comment but don't have the rep! While Maciej is entirely correct, and his answer helped me find my problem, savReaderWriter has since been updated. As of version 3.4.2 there are now 6 .dlyb files to be copied over.

Once you have your path to your folder (path is location of your error message), make sure to list ( ls in a terminal window) all files within that folder before creating your symlinks. Then create symlinks for each .dylib

Thanks again to Maciej for the great answer!

Overcome ibm_db import error (image not found) on MacOS, Overcome ibm_db import error (image not found) on MacOS 2): Library not loaded: libdb2.dylib ln -s clidriver/lib/libdb2.dylib libdb2.dylib. Step 4: Restart your terminal and pycharm (Python IDE) and try to “import ibm_db”,  Unfortunately, not all modules are compatible with Anaconda Python (as I can see from the log, you use it). The problem like this also appears for virtualenv.But regions documentation indicates the way to install it with conda.

For anyone else who is lazy:

ls /Users/your_user/anaconda/envs/quattro8/lib/python2.7/site-packages/savReaderWriter/spssio/macos/ | xargs -I {} sudo ln -s /Users/your_user/anaconda/envs/quattro8/lib/python2.7/site-packages/savReaderWriter/spssio/macos/{} /usr/local/lib/{}

This links all packages in that repo

QtCore.so: Reason Image Not Found -> Library not loaded: @rpath , QtCore.so: Reason Image Not Found -> Library not loaded: @rpath/libpyside.​cpython-34m.1.2.dylib Follow /Users/MyName/tensorflow/bin/python ImportError: dlopen(/Users/MyName/tensorflow/lib/python3.4/site-packages/​PySide/QtCore.so, 2): Library not loaded: @rpath/libpyside.cpython-34m.1.2. @ousmaneo, I had the same problem.Apparently it was caused by the fact that I didn't run sudo xcodebuild -license before attempting to install python3 (I'm an absolute beginner in the Mac world, but I guess some libraries failed to build because of this).

I am not a Mac person, but are you really using Python 3.6? Does the savReaderWriter support that version? I doubt that the I/o module it uses is built for that version.

If this works via Terminal but not an IDE, check that the Python search paths are the same.

Troubleshooting on Mac OS, dyld: Library not loaded: /usr/X11/lib/libX11.6.dylib Referenced from: image not found Error message: `There are not enough slots available in the system` /3.7.​2_2/Frameworks/Python.framework/Versions/3.7/lib/libpython3.7m.dylib"  In my case the custom widget for Designer was right and the dylib (libdline45vplugin.dylib) was correctly installed. Why do I need to rebuild the Creator from source to use the custom widget? I need to build a shared library for the widget to be used in app, libdl45v.1.dylib.

You can also specify the path to the libraries within PyCharm, which eliminates the need to create the symbolic links:

From the menubar click "Run" -> "Edit Configurations". In the left pane select the configuration for your python script (usually PyCharm creates a configuration for each .py-file). Insert the path to the libraries (shown in the error message) into "Environment Variables".

Example: DYLD_LIBRARY_PATH=/Users/username/miniconda3/envs/savreader/lib/python3.6/site-packages/savReaderWriter/spssio/macos;

Screenshot of PyCharm Run Configuration

brew upgrade broke Vim on OS X (dyld: Library not loaded), dyld: Library not loaded: /usr/local/opt/ruby/lib/libruby.2.4.1.dylib Referenced from​: /usr/local/bin/vim Reason: image not found error: vim died of signal 6 error: There was a problem with the editor 'vim'. Please supply the message using either  System: OSX 10.11, anaconda python distribution (2.3.0), ipython 4.0.0 version I try to load a module imported with easy_install. The module relies on some libraries which are correctly listed in DYLD_LIBRARY_PATH (they are in /usr/local

Cannot use terminal, Cannot use terminal - dyld: Library not loaded /libcrypto.1.0.0.dylib from: /usr/​local/opt/libevent/lib/libevent-2.1.6.dylib Reason: image not found [5] 2194 For one, you may try installing Python's IDLE and use it to run a script that'll execute  when trying to upgrade pytorch from 1.0.1 to 1.1, I ran into the same issue and found this thread. the update on linux server worked fine but not on my macbook (OSX) I tried brew install libomp but the brew formula could not be found, hence this did not fix the issue and I had to downgrade back to 1.0.1 on OSX to be able to import torch again

How to fix 'image not found' error related to 'Library not loaded: /usr , How to fix 'image not found' error related to 'Library not loaded: /usr/local/opt/​openssl/lib/libssl.1.0.0.dylib' when you import psycopg2 on  That sadly does not work for me. So far the only way I got the whole thing to work was: Running the export commands in the terminal. Opening python in the terminal.

Linking an OSX external bundle with a .dylib library, OSX dynamic libraries (file extension ".dylib") have an "install name" If it's not in that location in your system the library won't load. to run your stack from the IDE and have the externals working properly. Using Images 11. 🐛 Bug Install on MacOS fails with pip. To Reproduce (venv) whatlies git:(master) python -m pip install torch (venv) whatlies git:(master) python Python 3.7.7 (v3.7.7:d7c567b08f, Mar 10 2020, 02:56:16) [Clang 6.0 (clang-600.0.57)]

Comments
  • Although it doesn't support v3.6, it works for me ok (in terminal at least). All search paths that appear in terminal, appear in IDE as well.
  • In the same order? Weird.
  • Added sys.path output