Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Postgres suddenly raise error '/usr/lib/libpq.5.dylib' (no such file)

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

like image 900
Mahmoud Nasser Avatar asked Feb 01 '26 11:02

Mahmoud Nasser


2 Answers

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:

pip install --upgrade --force-reinstall psycopg2
like image 104
ruslanway Avatar answered Feb 03 '26 01:02

ruslanway


To solve this problem just run the following command:

sudo mkdir -p /usr/local/lib && sudo ln -s /opt/homebrew/opt/postgresql@14/lib/postgresql@14/libpq.5.dylib /usr/local/lib/libpq.5.dylib
like image 43
Mahmoud Nasser Avatar answered Feb 03 '26 01:02

Mahmoud Nasser



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!