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

by jsidell   Last Updated May 04, 2019 11:01 AM

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
(base) Jeffs-MacBook-Pro-2:~ jeffsidell$ echo $LD_LIBRARY_PATH
>>> 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.

Thanks for any help.

Related Questions

Updated April 28, 2015 03:00 AM

Updated May 15, 2019 17:01 PM

Updated May 30, 2019 15:01 PM