Right way to configure DYLD_LIBRARY_PATH, LD_LIBRARY_PATH for psycopg2 on Mac OS X (plus some other weirdness)

1

I installed Postgres, then psycopg2 on my Mac so that I can access Postgres from Python. The import statement is not working, because psycopg2 is not able to find the right versions (I believe) of some of the libraries. This was the case for libpq.dylib, but setting DYLD_LIBRARY_PATH to search in the Postgres directory first solved that issue:

(base) Jeffs-MacBook-Pro-2:~ jeffsidell$ echo $DYLD_LIBRARY_PATH
/Library/PostgreSQL/11/lib/:/usr/local/lib:/usr/lib
(base) Jeffs-MacBook-Pro-2:~ jeffsidell$ echo $LD_LIBRARY_PATH
/Library/PostgreSQL/11/lib/:/usr/local/lib:/usr/lib
>>> import psycopg2
ImportError: dlopen(/Users/jeffsidell/anaconda3/lib/python3.7/site-packages/psycopg2/_psycopg.cpython-37m-darwin.so, 2): Symbol not found: __cg_jpeg_resync_to_restart
  Referenced from: /System/Library/Frameworks/ImageIO.framework/Versions/A/ImageIO
  Expected in: /usr/local/lib/libJPEG.dylib
 in /System/Library/Frameworks/ImageIO.framework/Versions/A/ImageIO

I looked for other (newer) versions of libJPEG.dylib in my Postgres installation, but it appears not to be included with Postgres:

(base) Jeffs-MacBook-Pro-2:~ jeffsidell$ cd /Library/PostgreSQL/11/lib
(base) Jeffs-MacBook-Pro-2:lib jeffsidell$ ls *JPEG*
ls: *JPEG*: No such file or directory

Checking /usr/local/lib, libjpeg.dylib does exist, so likely it's a versioning issue. (And for those wondering, like I did, why libjpeg.dylib == libJPEG.dylib, see here.

I tried reinstalling psycopg2, but that didn't solve the issue.

(Update): I found a version of libjpeg.dylib in a Postgres sub-directory, so added it to DYLD_LIBRARY_PATH:

echo $DYLD_LIBRARY_PATH
/Library/PostgreSQL/11/lib/:/Library/PostgreSQL/11/stackbuilder.app/Contents/Frameworks/:/usr/local/lib:/usr/lib/

Now, there appears to be an incompatibility between the Postgres version of libjpeg.dylib and another library, libtiff.dylib, which doesn't appear anywhere other than /usr/local/lib:

>>> import psycopg2
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/jeffsidell/anaconda3/lib/python3.7/site-packages/psycopg2/__init__.py", line 50, in <module>
    from psycopg2._psycopg import (                     # noqa
ImportError: dlopen(/Users/jeffsidell/anaconda3/lib/python3.7/site-packages/psycopg2/_psycopg.cpython-37m-darwin.so, 2): Library not loaded: /usr/local/opt/jpeg/lib/libjpeg.9.dylib
  Referenced from: /usr/local/lib/libTIFF.dylib
  Reason: Incompatible library version: libTIFF.dylib requires version 13.0.0 or later, but libJPEG.dylib provides version 11.0.0

Thanks for any help.

jsidell

Posted 2019-05-04T10:27:25.307

Reputation: 51

No answers