Skip to content

Instantly share code, notes, and snippets.

@JoshuaGross
Created November 28, 2016 07:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JoshuaGross/2b4708986906503bd25f5845d3305045 to your computer and use it in GitHub Desktop.
Save JoshuaGross/2b4708986906503bd25f5845d3305045 to your computer and use it in GitHub Desktop.
OS X El Capitan, "Reason: image not found" - Python library loading error resolution

Python "image not found" error resolution

This is an error that seems to occur on OS X El Capitan. You may see errors like this that did not occur before:

$ ./my_python_script.py
Traceback (most recent call last):
  File "./my_python_script.py", line 17, in <module>
    import psycopg2
  File "/Users/joshuagross/miniconda2/envs/my_env/lib/python2.7/site-packages/psycopg2/__init__.py", line 50, in <module>
    from psycopg2._psycopg import BINARY, NUMBER, STRING, DATETIME, ROWID
ImportError: dlopen(/Users/joshuagross/miniconda2/envs/my_env/lib/python2.7/site-packages/psycopg2/_psycopg.so, 2): Library not loaded: /Library/PostgreSQL/9.4/lib/libcrypto.1.0.0.dylib
  Referenced from: /Users/joshuagross/miniconda2/envs/my_env/lib/python2.7/site-packages/psycopg2/_psycopg.so
  Reason: image not found

There are several StackOverflow questions about this, but only one answer worked for me, which is to change library paths to be absolute paths in _psycopg.so:

$ sudo install_name_tool -change libcrypto.1.0.0.dylib /Users/joshuagross/miniconda2/lib/libcrypto.1.0.0.dylib /Users/joshuagross/miniconda2/envs/hitl_tools/lib/python2.7/site-packages/psycopg2/_psycopg.so
$ sudo install_name_tool -change libcrypto.1.0.0.dylib /Users/joshuagross/miniconda2/lib/libcrypto.1.0.0.dylib /Users/joshuagross/miniconda2/envs/hitl_tools/lib/python2.7/site-packages/psycopg2/_psycopg.so
$ sudo install_name_tool -change libssl.1.0.0.dylib /Users/joshuagross/miniconda2/lib/libssl.1.0.0.dylib /Users/joshuagross/miniconda2/envs/hitl_tools/lib/python2.7/site-packages/psycopg2/_psycopg.so

Of course, YMMV and I didn't investigate root-causes of this. It seems to be particular to OS X El Cap, and perhaps also to Conda.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment