Can't change library version of PostgreSQL with psycopg2

42 Views Asked by At

I've installed Postgresapp app with Postgresql v16 before and using it for a while. Then I realized that sometimes I'm having problems with migrations so I've tried to fix and deep into the problem. And found out that, it's using PostgreSQL client version 16 provided by Postgresapp in psycopg2, but we are using PostgreSQL 13 in production so I've decided to downgrade it in my local environment.

I've uninstalled Postgresapp and installed Postgresql v13 with brew (and also tried with PostgreSQL v13 provided in Postgresapp) but it's still looking for PostgreSQL v16 libraries, I'm getting this error.

  Referenced from: <6C63B347-6EF3-3651-8D8C-F7B5D56B0B8E> /Users/xxxx/Library/Caches/pypoetry/virtualenvs/project-NfM96__V-py3.11/lib/python3.11/site-packages/psycopg2/_psycopg.cpython-311-darwin.so
  Reason: tried: '/Applications/Postgres.app/Contents/Versions/16/lib/libpq.5.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/Applications/Postgres.app/Contents/Versions/16/lib/libpq.5.dylib' (no such file), '/Applications/Postgres.app/Contents/Versions/16/lib/libpq.5.dylib' (no such file)

I don't want to do any hacky solution like symlinking, it's just a coverage. So how can I change this reference to the correct path? I've reinstalled postgres@13 with brew, reinstalled psycopg2, and reinstalled poetry environment but it's still looking for the wrong path.

Any suggestions?

ps: Later, I've found out that it's working with psycopg2-binary, or if I build as wheel it's working, is that the correct way to do it?

1

There are 1 best solutions below

0
tanaydin On

I've started using psycopg2-binary, and it is working with it.