48

Currently I am installing psycopg2 for work within eclipse with python.

I am finding a lot of problems:

  1. The first problem sudo pip3.4 install psycopg2 is not working and it is showing the following message

Error: pg_config executable not found.

FIXED WITH:export PATH=/Library/PostgreSQL/9.4/bin/:"$PATH”

  1. When I import psycopg2 in my project i obtein:

ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/psycopg2/_psycopg.so Library libssl.1.0.0.dylib Library libcrypto.1.0.0.dylib

FIXED WITH: sudo ln -s /Library/PostgreSQL/9.4/lib/libssl.1.0.0.dylib /usr/lib sudo ln -s /Library/PostgreSQL/9.4/lib/libcrypto.1.0.0.dylib /usr/lib

  1. Now I am obtaining:

ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/psycopg2/_psycopg.so, 2): Symbol not found: _lo_lseek64 Referenced from: /Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/psycopg2/_psycopg.so Expected in: /usr/lib/libpq.5.dylib in /Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/psycopg2/_psycopg.so

Can you help me?

ROMANIA_engineer
  • 54,432
  • 29
  • 203
  • 199
Benja Garrido
  • 701
  • 1
  • 5
  • 17

8 Answers8

77

You need to replace the /usr/lib/libpq.5.dylib library because its version is too old.
Here's my solution to this problem:

$ sudo mv /usr/lib/libpq.5.dylib /usr/lib/libpq.5.dylib.old  
$ sudo ln -s /Library/PostgreSQL/9.4/lib/libpq.5.dylib /usr/lib
KungFuLucky7
  • 825
  • 7
  • 7
  • Thank you @KungFuLucky7 I will try it and i will say you – Benja Garrido Feb 20 '15 at 11:48
  • 4
    This worked for me after upgrading to Yosemite. If you're using the postgres app then the second command should be: sudo ln -s /Applications/Postgres.app/Contents/MacOS/lib/libpq.5.dylib /usr/lib – tarequeh Mar 08 '15 at 22:27
  • 2
    I'm seeing ln: /usr/lib/libpq.5.dylib: Operation not permitted – allthesignals Jan 19 '16 at 15:18
  • Great: http://stackoverflow.com/questions/32659348/operation-not-permitted-when-on-root-el-capitan-rootless-disabled. So I have to go into recovery mode, disable System Integrity Protection, and then relink the libraries. – allthesignals Jan 19 '16 at 15:25
28

If you are using PostgresApp, you need to run the following two commands:

sudo mv /usr/lib/libpq.5.dylib /usr/lib/libpq.5.dylib.old
sudo ln -s /Applications/Postgres.app/Contents/Versions/9.4/lib/libpq.5.dylib /usr/lib
Samer
  • 667
  • 1
  • 5
  • 11
  • This worked for me. But I am proceeding cautiously. The thing that I am unclear about, is how this could affect other apps on my system that are dependent on a previous version of PostgreSQL that is installed on my system (OSX Mavericks). – JayGee Sep 08 '15 at 00:15
  • This works for me. I had a Postgresql installed before, and then I installed the PostgreSQL app, the same error occured when I uninstalled the previous installation. And this question solves my problem, not sure why, but kudos! – benjaminz Nov 25 '15 at 12:30
15

I was able to fix this on my Mac (running Catalina, 10.15.3) by using psycopg2-binary rather than psycopg2.

pip3 uninstall psycopg2 pip3 install psycopg2-binary

jgshurts
  • 709
  • 5
  • 7
4

I am using yosemite, postgres.app & django. this got psycopg2 to load properly for me but the one difference was that my libpq.5.dylib file is in /Applications/Postgres.app/Contents/Versions/9.4/lib.

thus my second line was sudo ln -s /Applications/Postgres.app/Contents/Versions/9.4/lib/libpq.5.dylib /usr/lib

ksmskm
  • 81
  • 1
  • 3
4

Here's a fix that worked for me on El Capitan that doesn't require restarting to work around the OS X El Capitan System Integrity Protection (SIP):

brew unlink postgresql && brew link postgresql
brew link --overwrite postgresql

H/T Farhan Ahmad

Dusk
  • 71
  • 3
  • On my OS X Yosemite 10.10.3, I had to add -force and the --overwrite wasn't needed: brew unlink postgresql94 && brew link -force postgresql94 – Mike Lapinskas Apr 22 '18 at 15:33
  • 1
    Using the official Postgresql install .dmg caused some of these errors for me. Reinstalling using brew seemed to do the trick. – Simon Tower Jul 11 '19 at 20:54
2

For those of you on El Capitan who can't use @KungFuLucky7's answer - I used the following to fix the issue (Adjust paths to match yours where required).

sudo install_name_tool -change libpq.5.dylib /Library/PostgreSQL/9.5/lib/libpq.5.dylib /usr/local/lib/python2.7/site-packages/psycopg2/_psycopg.so
Steve Forbes
  • 230
  • 1
  • 6
1

In El Capitan, I used the same solution as @Forbze but 2 more commands as follows.

sudo install_name_tool -change libpq.5.dylib /Library/PostgreSQL/9.3/lib/libpq.5.dylib  /Library/Python/2.7/site-packages/psycopg2/_psycopg.so
sudo install_name_tool -change libssl.1.0.0.dylib /Library/PostgreSQL/9.3/lib/libssl.1.0.0.dylib  /Library/Python/2.7/site-packages/psycopg2/_psycopg.so
sudo install_name_tool -change libcrypto.1.0.0.dylib /Library/PostgreSQL/9.3/lib/libcrypto.1.0.0.dylib  /Library/Python/2.7/site-packages/psycopg2/_psycopg.so

It works perfectly!

Hung Dam
  • 109
  • 1
  • 3
0

well, I'd like to give my solution, the problem is related with the version of c. So, I just typed:

CFLAGS='-std=c99' pip install psycopg2==2.6.1
carlos.rivera
  • 71
  • 1
  • 7