I am trying to run a Django project with Postgres database. I use Postgres 13.4 installed via postgressapp (UNIVERSAL with all currently supported versions) and python 3.9 (in venv). I work on Mac with Apple M1 chip, macOS Big Sur.
I faced the following well-known problem:
django.core.exceptions.ImproperlyConfigured: Error loading psycopg2 module: dlopen(/Users/mymac/PyCharmProjects/projectname/venv/lib/python3.9/site-packages/psycopg2/_psycopg.cpython-39-darwin.so, 2): Library not loaded: /opt/homebrew/opt/postgresql/lib/libpq.5.dylib
Referenced from: /Users/mymac/PyCharmProjects/projectname/venv/lib/python3.9/site-packages/psycopg2/_psycopg.cpython-39-darwin.so
Reason: image not found
With searching, I found some discussions like this: https://github.com/psycopg/psycopg2/issues/1216
. It seems that the most relevant solution is "RyanDurk commented on Jan 27":
$ brew install libpq --build-from-source
$ export LDFLAGS="-L/opt/homebrew/opt/libpq/lib"
$ pip install psycopg2
Unfortunately, in my case it does not help.
Then, I found some recommendations here: Library not loaded: /usr/local/lib/libpq.5.4.dylib and tried them. In particular, I tried to reach libpq.5.dylib via symlink like:
ln -s /Library/PostgreSQL/13/lib/libpq.5.dylib /opt/homebrew/opt/postgresql/lib/libpq.5.dylib
(the solution marked as accepted by topic starter), but also unsuccessfully.
I tried to install postgres from postgresql.org, then uninstall/reinstall postgres with homebrew, then
gem uninstall pg -> bundle install
with the same result.
I have run the same project successfully before, on the mac with Intel chip and PyCharm community edition. Also the same project runs normally on Linux.
If you have any idea what happens and how to fix this problem, please help me. I provide more details if necessary.
pip install psycopg2-binary
? – NowakRequirement already satisfied: psycopg2-binary in /Users/myMac/PyCharmProjects/myProject/venv/lib/python3.9/site-packages (2.9.1)
– Padgem install
is a Ruby thing and not going to help with this. – Nowak