when I run Django project or any code related to Postgres :
Referenced from: '/Users/mahmoudnasser/.local/share/virtualenvs/wyspp_backend-PwdII1PB/lib/python3.8/site-packages/psycopg2/_psycopg.cpython-38-darwin.so'
Reason: tried: '/opt/homebrew/opt/postgresql/lib/libpq.5.dylib' (no such file), '/usr/local/lib/libpq.5.dylib' (no such file), '/usr/lib/libpq.5.dylib' (no such file)
I tried many solutions online but none of them worked.
Note: I use MacOS
3
Answers
To solve this problem just run the following command:
Something similar happened to me following a
brew
PostgreSQL upgrade. The solution to my problem was to delete my virtual environment, in my case.venv
, and rerun:After that, I was able to start my application with no problem.
I think the issue was the result of an outdated dependency graph. Re-installing the dependencies with pip found the new version of Postgres and linked the
libpq.5.dylib
correctly.Note, I was using the following
psycopg2
dependency:For what it’s worth, I am also on
MacOS Monterey
and this just happened in a second codebase on the same machine.The exact error was:
I have just encountered with this problem after upgrade Postgres with homwbrew.
So I try to reinstall psycopg2 in my venv and that’s solve it.
Now it’s ok. Just try: