Trying to setup postgres with the postgres mac app and hit this error, which I haven’t been able to solve. Any thoughts?
ImportError: dlopen(/Users/Craig/pyenv/mysite/lib/python2.7/site-packages/psycopg2/_psycopg.so, 2): Library not loaded: /../lib/libssl.1.0.0.dylib Referenced from: /Applications/Postgres.app/Contents/MacOS/lib/libpq.dylib Reason: image not found
$ sudo ln -s /Library/PostgreSQL/9.2/lib/libssl.1.0.0.dylib /usr/lib $ sudo ln -s /Library/PostgreSQL/9.2/lib/libcrypto.1.0.0.dylib /usr/lib
I encountered this error while working on Django.
I have it working on virtualenv with Django==1.3 but not on Django==1.5 where I have to issue the commands above.
In OS X El Capitan you can’t do these links without disabling system protection but it works well if you link to /usr/local/lib
pip install psycopg2-binary
works like a charm!
Discussion on source+wheel distribution (pyscopg2) vs a separate binary distribution (psycopg2-binary): https://www.postgresql.org/message-id/CA%2Bmi_8bd6kJHLTGkuyHSnqcgDrJ1uHgQWvXCKQFD3tPQBUa2Bw%40mail.gmail.com
Explanation on the decision to release psycopg2-binary: http://initd.org/psycopg/articles/2018/02/08/psycopg-274-released/
However, there are reports of psycopg2-binary not satisfying psycopg2 dependencies. More discussion here: https://github.com/psycopg/psycopg2/issues/674
I found a solution that worked for me when dealing with a similar issue on rails. Add the following to your .bash_profile, .bash_rc, or equivalent:
(Assuming you installed Postgres.app in the default location). Then restart your terminal session and try again.
Exporting to DYLD_LIBRARY_PATH directly can cause serious problems with other apps that depend on it, but using the fallback path avoids these problems.
EDIT: It seems that setting DYLD_FALLBACK_LIBRARY_PATH causes an error when you try to run psql. To fix this, you can add the following two lines to your .bash_profile:
alias psql="(. ~/.bash_profile; unset DYLD_FALLBACK_LIBRARY_PATH; psql)";
This is assuming that you’re using bash and that your .bash_profile is located in your home directory. If that’s not the case (or if you’re using a .bashrc or other environment setup instead of .bash_profile) change the
~/.bash_profile part of the command to the path to your environment setup script.
The aliased command basically starts a subshell which does not effect your current bash environment. So when it unsets the DYLD_FALLBACK_LIBRARY_PATH variable, it’s only temporary. After you exit psql the environment variable will be set again.
This happened to me after upgrading Postgresql, and after installing psycopg2 in my virtualenv. Reinstalling (re-building) worked for me.
pip uninstall psycopg2 pip install psycopg2
This problem cost me the whole morning to solve. I found the discussion on http://initd.org/psycopg/articles/2010/11/11/links-about-building-psycopg-mac-os-x/ really helpful. Thanks to Jurie’s answer, the solution to my problem (in Mac) is as below:
Install openssl 1.0.0 using brew:
brew install openssl
using the following command:
replace 1.0.1x part with your current version. For me it is 1.0.1h.
Hope this helps!
EDIT: After one day, I found that the second command has to be entered every time when needing to connect to database, so not a permanent solution to this problem.
In your bash environment before you load it, try this:
..replacing the ‘x.y’ with the version on your system.
..be aware that setting this in your bash profile can interfere with other programs, as KindOfGuy noted.
..of course, if you’re not running it from a bash prompt, you’ll have to set up your environment in whatever way pyenv lets you. ..you could even edit pyenv itself and place that at the top.
Another alternative is to put this in a python script which runs before you attempt to import psycopg2:
import os os.environ['DYLD_LIBRARY_PATH'] = '/Library/PostgreSQL/x.y/lib'
..again, replacing ‘x.y’ with the version on your system in /Library/PostgreSQL.
I encountered this issue when I upgraded from postgres.app 9.4 to 9.5 on el capitan.
The other solutions will not work (easily) in el capitan because of the system lock on certain directories, meaning the symbolic link solution will be less accessible/ideal for most.
This leaves the fallback variable. The current answer points to the wrong directory. I am guessing the dylibs directory has changed since 2013.
So, here is the latest fallback directory that works for me:
Under Mac OS X 10.11 (El Capitan),
/usr/lib is read only for root user.
You’ll get a
ln: /usr/lib/libssl.1.0.0.dylib: Operation not permitted error
You need to use
/usr/local/lib instead of
sudo ln -s /Library/PostgreSQL/9.2/lib/libssl.1.0.0.dylib /usr/local/lib sudo ln -s /Library/PostgreSQL/9.2/lib/libcrypto.1.0.0.dylib /usr/local/lib