[Fixed]-Error loading psycopg2 module: Library not loaded: libpq.5.dylib

31πŸ‘

βœ…

I had the same error after brew decided to upgrade my postgresql package to version 14 (your version may vary).

There was this part of the error message:

Library not loaded: '/usr/local/opt/postgresql/lib/libpq.5.dylib'
...
Reason: tried: '/usr/local/opt/postgresql/lib/libpq.5.dylib' (no such file)

I basically found the new location of the libpq and symlinked it to the location where psycopg2 was looking for it:

ln -s /usr/local/lib/postgresql@14/libpq.5.14.dylib /usr/local/opt/postgresql/lib/libpq.5.dylib

Hope that helps anyone else with a similar issue.

πŸ‘€alecxe

1πŸ‘

I ran into the same error this morning. My solution is a bit different than the accepted one :

I uninstalled and reinstalled psycopg2.

pip uninstall psycopg2

pip install -r requirements.txt

No version change here but I guess the build process identified the right path.

πŸ‘€SΓ©raphin

Leave a comment