MacOS Catalina: Symbol not found: _PQsslAttribute

Viewed 680

I uninstalled Old PgSQL 9 and installed the latest one PgSQL12 app. When I am trying to import psycopg2 I am getting the following error:

>>> import psycopg2
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/AdnanAhmad/Data/anaconda3/lib/python3.7/site-packages/psycopg2/__init__.py", line 50, in <module>
    from psycopg2._psycopg import (                     # noqa
ImportError: dlopen(/Users/AdnanAhmad/Data/anaconda3/lib/python3.7/site-packages/psycopg2/_psycopg.cpython-37m-darwin.so, 2): Symbol not found: _PQsslAttribute
  Referenced from: /Users/AdnanAhmad/Data/anaconda3/lib/python3.7/site-packages/psycopg2/_psycopg.cpython-37m-darwin.so
  Expected in: /usr/lib/libpq.5.dylib
 in /Users/AdnanAhmad/Data/anaconda3/lib/python3.7/site-packages/psycopg2/_psycopg.cpython-37m-darwin.so
1 Answers

I was getting the same error message (Python3, MacOS 10.14.6) and was able to fix it by doing the following:

sudo install_name_tool -change libpq.5.dylib /Library/PostgreSQL/9.6//lib/libpq.5.dylib /usr/local/lib/python3.7/site-packages /psycopg2/_psycopg.cpython-37m-darwin.so

sudo install_name_tool -change libssl.1.1.dylib /Library/PostgreSQL/9.6//lib/libssl.1.1.dylib /usr/local/lib/python3.7/site-packages/psycopg2/_psycopg.cpython-37m-darwin.so

sudo install_name_tool -change libcrypto.1.1.dylib /Library/PostgreSQL/9.6//lib/libcrypto.1.1.dylib /usr/local/lib/python3.7/site-packages/psycopg2/_psycopg.cpython-37m-darwin.so

You'll need to adjust your path names (obviously), both for the python site-packages directory, and the directory where the Postgres .dylib libraries above live. Also, the name of the _psycopg*.so library may/will likely be different on your system. No promises that it'll solve it for you (also obviously :) Good luck!

Related