python pip install psycopg2 install error

2019-01-06 15:14发布

问题:

I did a simple pip install psycopg2 on mac system. It installed fine, but when I try to use psycopg2 I get the error:

Reason: Incompatible library version: _psycopg.so requires version 1.0.0 or later, but libssl.0.9.8.dylib provides version 0.9.8

pip freeze shows psycopg2==2.4.5 just right. I have installed psycopg2 on several virtualenvs but this is the first time I am seeing such error. I tried uninstalling and reinstalling, same results. Please help

回答1:

I ran into a similar problem after upgrading to Mountain Lion.

Instead of copying libssl.* files per Slack's suggestion, make sure that /usr/lib/libssl.dylib is actually a soft link to the most up-to-date version of the library.

E.g., on my machine, ls -l /usr/lib/libssl* gives:

lrwxr-xr-x  1 root  wheel    46B Jun 27 15:24 /usr/lib/libssl.1.0.0.dylib -> /Library/PostgreSQL/9.1/lib/libssl.1.0.0.dylib
lrwxr-xr-x  1 root  wheel    27B Jul 30 10:31 /usr/lib/libssl.dylib -> /usr/lib/libssl.1.0.0.dylib

If libssl.dylib doesn't link to the version that the error version mentions, make sure you have that version of the library, and then make sure /usr/lib/libssl.dylib points to it, and not an older version.

If the link doesn't exist, create it like so

sudo ln -s library_to_link_to link_to_create

using, of course, the proper locations for your machine. For me, this turned out to be:

sudo ln -s /usr/lib/libssl.1.0.0.dylib /usr/lib/libssl.dylib

Edit:

It seems like some are having trouble with part of my solution. Namely, deleting these important libraries even temporarily causes problems with the operating system.

Per Purrell's answer, make sure you include the -fs flags when you use the ln command, which helps ensure that the libraries don't go missing for a short period of time. E.g.,

sudo ln -fs /usr/lib/libssl.1.0.0.dylib /usr/lib/libssl.dylib
sudo ln -fs /usr/lib/libcrypto.1.0.0.dylib /usr/lib/libcrypto.dylib


回答2:

The accepted answer here is correct (except I think it must be ln -fs , in fact I think it might even risk destabalizing your OS if not (?)). After bumping into this and dealing with it I just want to collect the full solution for this issue and the other lib problem (libcrypto.1.0.0.dylib) you will run into for Postgres 9.* on Mountain Lion and Snow Leopard, and perhaps other systems. This also blocked me from running psql, which complained about the same two libs.

Essentially there are two later-version libs needed in /usr/lib, libssl and libcrypto. You can find the needed versions of these libs in the Postgres lib directory.

  • If you're OSX and installed the Enterprise DB version of Postgres this will be in /Library/PostgreSQL/9.2/lib.
  • For other install types of Postgres, look for the lib directory inside the Postgress install directory, e.g., for Postgress.app, find the lib directory in /Applications/Postgres.app/Contents/MacOS/lib,
  • for brew somewhere in /usr/local/Cellar,
  • on *nix, wherever your install is. But see first on *nix if your distro has later versions just through the package manager.

First copy the latest of these two libs from the Postgres lib directory to /usr/lib:

sudo cp /Library/PostgreSQL/9.2/lib/libssl.1.0.0.dylib /usr/lib
sudo cp /Library/PostgreSQL/9.2/lib/libcrypto.1.0.0.dylib /usr/lib

Then update (or create) the /usr/lib symlinks for this libs. Either way the command is ln -fs:

sudo ln -fs /usr/lib/libssl.1.0.0.dylib /usr/lib/libssl.dylib
sudo ln -fs /usr/lib/libcrypto.1.0.0.dylib /usr/lib/libcrypto.dylib

Should be fixed. Pretty sure ln -fs is better than deleting the symlink and remaking it, so there is less chance of libssl being unfindable by something that needs it for the time it is not present (it does the same thing; it first deletes the symlink if it's already there, just faster than you can type it). Always wary of messing around on /usr/lib.



回答3:

When trying to do a syncdb Postgres 9.1 and /psycopg2/_psycopg.so added a further error:

Library not loaded: @loader_path/../lib/libcrypto.dylib Referenced from: /usr/lib/libpq.5.dylib Reason: Incompatible library version: libpq.5.dylib requires version 1.0.0 or later, but libcrypto.0.9.8.dylib provides version 0.9.8

Solved by copying these six (6) files from:

LOCAL:/Library/PostgreSQL/9.1/lib/

libssl.1.0.0.dylib

libssl.a

libssl.dylib

libcrypto.1.0.0.dylib

libcrypto.a

libcrypto.dylib

to: LOCAL:/usr/lib

This was on Mac OSx 10.8.1 with a web in a virtualenv (1.8.2) and pgAdmin (1.14.3). Inside the virtualenv is:

Django==1.4

psycopg2==2.4.5

... etc... and now back to normal.



回答4:

For me, the libcryto and libss version 1.0.0 resides below:

/Library/PostgreSQL/9.1/lib/libcrypto.1.0.0.dylib
/Library/PostgreSQL/9.1/lib/libssl.1.0.0.dylib

so the commands that fix my problem is:

sudo ln -fs /Library/PostgreSQL/9.1/lib/libssl.1.0.0.dylib /usr/lib/libssl.dylib
sudo ln -fs /Library/PostgreSQL/9.1/lib/libcrypto.1.0.0.dylib /usr/lib/libcrypto.dylib


回答5:

On OSX 10.11, El Capitan, solution with replacing symlinks reported Operation not permitted. Solution that worked for me was using brew and setting up DYLD_LIBRARY_PATH. So:

brew install openssl

Find where openssl brew libs are located, start searching from directory /usr/local/Cellar/openssl. In my case it is in /usr/local/Cellar/openssl/1.0.2d_1/lib

Finally set up DYLD_LIBRARY_PATH, i.e. add a line like this into .bash_profile :

# replace location of lib files with folder name you found in previous step
export DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH:/usr/local/Cellar/openssl/1.0.2d_1/lib

restart shell, or just source ~/.bash_profile, reinstall psycopg2:

pip uninstall psycopg2
pip install psycopg2

and test if it works:

$ python -c"import psycopg2  ;   print('psycopg2 is now ok')"


回答6:

my friend, just copy libssl.* files from PostgreSQL lib directory to /usr/lib and relaunch your application in this case all things will be perfect ^_^



回答7:

For me on Mavericks, it worked to just copy the two dylib and relaunch Python:

cp /Library/PostgreSQL/9.3/lib/libssl.1.0.0.dylib /usr/lib/
cp /Library/PostgreSQL/9.3/lib/libcrypto.1.0.0.dylib /usr/lib/


回答8:

If you are uncomfortable copying libraries into your system directory, you can use the DYLD_LIBRARY_PATH environment variable to force the OS to search Postgres's library directory for libssl. E.g.:

$ DYLD_LIBRARY_PATH=/Library/PostgreSQL/9.4/lib pip install psycopg2

(documented under the dyld man page).