18

I recently uninstalled postgresql and installed pyscopg2 via pip.

I know there's some trickery involved with libcrypto and libssl

Currently i have them symlinked to:

$ ls -lah libssl.*
-rwxr-xr-x  1 root  wheel   402K Aug 28 11:06 libssl.0.9.7.dylib
-rwxr-xr-x  1 root  wheel   589K Aug 28 11:06 libssl.0.9.8.dylib
lrwxr-xr-x  1 root  wheel    55B Nov 29 23:38 libssl.1.0.0.dylib -> /usr/local/Cellar/openssl/1.0.1c/lib/libssl.1.0.0.dylib
lrwxr-xr-x  1 root  wheel    55B Nov 30 02:25 libssl.dylib -> /usr/local/Cellar/openssl/1.0.1c/lib/libssl.1.0.0.dylib

/usr/lib
$ ls -lah libcrypto.*
-rwxr-xr-x  1 root  wheel   2.1M Aug 28 11:06 libcrypto.0.9.7.dylib
-rwxr-xr-x  1 root  wheel   2.6M Aug 28 11:06 libcrypto.0.9.8.dylib
-r-xr-xr-x  1 root  wheel   1.6M Oct 31 22:12 libcrypto.1.0.0.dylib
lrwxr-xr-x  1 root  wheel    58B Nov 30 02:27 libcrypto.dylib -> /usr/local/Cellar/openssl/1.0.1c/lib/libcrypto.1.0.0.dylib

whereby I installed openssl via ports

Now when I run arc diff, I am getting the infamous

$ arc diff
dyld: Library not loaded: /usr/lib/libpq.5.dylib
  Referenced from: /usr/bin/php
  Reason: image not found
Trace/BPT trap: 5

There are a few answers here in SO which talks about symlinking these libs to the postgresql install directory. Obviously, this won't work for me.

What should I do?

xjq233p_1
  • 7,810
  • 11
  • 61
  • 107
  • What's `arc`? Also, I see `/usr/bin/php`; that doesn't look very Python to me. And if you *un*installed postgresql, I'm not so sure that `pip` will install postgresql for you if you install `psycopg2` (though, if it doesn't, it should probably fail). Do you have a libpq (any) on your system? –  Nov 30 '12 at 12:49
  • Related?: [Library not loaded: /usr/local/lib/libpq.5.4.dylib while running rake db:create](http://stackoverflow.com/q/9023482/456814). –  May 20 '14 at 23:06

8 Answers8

16

Turns out /usr/lib/libpq.5.dylib was absent but /usr/lib/libpq.5.4.dylib was not.

sudo ln -s /usr/lib/libpq.5.4.dylib /usr/lib/libpq.5.dylib

fixed the issue.

Alex Reynolds
  • 95,983
  • 54
  • 240
  • 345
xjq233p_1
  • 7,810
  • 11
  • 61
  • 107
14

just use the below commands in your terminal (use the proper postgresql version) $ brew unlink postgresql@14

$ brew link libpq --force

https://github.com/opentable/otj-pg-embedded/issues/152#issuecomment-954348544

Akshay-stori
  • 141
  • 1
  • 3
  • This did work for me but then another project broke because it needed `postgresql@14` linked. Instead I reinstalled all my python project modules including psycopg2 by setting `export LDFLAGS="-L/usr/local/opt/libpq/lib"` first. – mochatiger Oct 27 '22 at 22:54
9

I got the error

Library not loaded: '/usr/local/opt/postgresql/lib/libpq.5.dylib'

Reason: tried: '/usr/local/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)

when running a Django project and to fix it I had to uninstall the pip packages:

pip uninstall psycopg2 
pip uninstall psycopg2-binary 

and then install them again:

pip install psycopg2 
pip install psycopg2-binary 

And this made the project run without the error.

DevB2F
  • 4,674
  • 4
  • 36
  • 60
3

Not unlike @Pablo Marambio, I fixed this issue by adding the following line to ~/.profile:

export DYLD_LIBRARY_PATH=/Library/PostgreSQL/9.3/lib:$DYLD_LIBRARY_PATH

For Postgres.app v9.3.5.0 (presumably others too) I added the following line instead:

export DYLD_LIBRARY_PATH=/Applications/Postgres.app/Contents/Versions/9.3/lib:$DYLD_LIBRARY_PATH

Then, of course, run source ~/.profile

metasequoia
  • 7,014
  • 5
  • 41
  • 54
  • 1
    I like this exporting environment variable better than copying or symlinking libraries on my system. – Sam Texas Dec 25 '14 at 20:48
  • This breaks running "psql DBNAME" in the command line for me. Running Postgres.app v9.5.0.0 and the error returned says "dyld: Symbol not found: __cg_jpeg_resync_to_restart" – Raymond26 Jun 06 '16 at 23:39
2

To resolve this, I had to uninstall postgresql and then install again.

$ brew uninstall postgresql

$ brew update

$ brew install postgres
SuperNova
  • 25,512
  • 7
  • 93
  • 64
1

I had to do this for postgresql 14 + brew

sudo ln -s /opt/homebrew/opt/postgresql@14/lib/postgresql@14/libpq.5.dylib /opt/homebrew/opt/postgresql/lib/libpq.5.dylib
Frexuz
  • 4,732
  • 2
  • 37
  • 54
0

I'm using poetry so to solve it on my fastapi project, I had to do this to fix it:

poetry remove psycopg2
poetry add psycopg2
zekromWex
  • 280
  • 1
  • 4
  • 17
0

It try to load libpq.5.dylib from the symlink /opt/homebrew/opt/postgresql/lib/libpq.5.dylib but found not file, so you need to update it:

# TODO: get this from the error, after "Library not loaded:"
SYMLINK_PATH="/usr/lib/libpq.5.dylib"

# TODO: find this in your machine. The version maybe different than mine
DESTINATION_PATH="/opt/homebrew/opt/postgresql/lib/postgresql@14/libpq.5.dylib"

sudo mv $SYMLINK_PATH $SYMLINK_PATH.old
sudo ln -s $DESTINATION_PATH $SYMLINK_PATH