Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't install psycopg2 with pip in virtualenv on Mac OS X 10.7

I am following Heroku's tutorial to deploy a Django app: http://devcenter.heroku.com/articles/django#prerequisites.

Everything is working fine until I get to this part:

$ pip install Django psycopg2 

I can install Django by itself, but the probelm is with psycopg2.

I keep getting this error:

ld: library not found for -lpq  collect2: ld returned 1 exit status  ld: library not found for -lpq  collect2: ld returned 1 exit status  lipo: can't open input file: /var/folders/_4/p6l0y0t51hd4xbq7llbyshmw0000gn/T//cc0L10mI.out (No such file or directory)  error: command 'gcc-4.2' failed with exit status 1 

I've installed PostgreSQL 9.1 on my machine.

Also, in the output, there are bunch of lines like this:

gcc-4.2 -fno-strict-aliasing -fno-common -dynamic -isysroot /Developer/SDKs/MacOSX10.6.sdk -arch i386 -arch x86_64 -g -O2 -DNDEBUG -g -O3 -DPSYCOPG_DEFAULT_PYDATETIME=1 -DPSYCOPG_VERSION="2.4.4 (dt dec pq3 ext)" -DPG_VERSION_HEX=0x090004 -DPSYCOPG_EXTENSIONS=1 -DPSYCOPG_NEW_BOOLEAN=1 -DHAVE_PQFREEMEM=1 -I/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -I. -I/usr/include -I/usr/include/postgresql/server -c psycopg/typecast.c -o build/temp.macosx-10.6-intel-2.7/psycopg/typecast.o 

I'm not really sure what it means, but I do notice that it has "macosx-10.6" in it so I'm wondering if that could be the issue? I'm on 10.7.

Thanks in advance for your help.

like image 316
WarAndPiece Avatar asked Mar 13 '12 04:03

WarAndPiece


People also ask

Does psycopg2 work with Python 3?

The current psycopg2 implementation supports: Python 2 versions from 2.6 to 2.7. Python 3 versions from 3.2 to 3.6. PostgreSQL server versions from 7.4 to 9.6.

Could not find a version that satisfies the requirement psycopg2?

Queries related to “could not find a version that satisfies the requirement psycopg2” You may install a binary package by installing 'psycopg2-binary' from PyPI. If you want to install psycopg2 from source, please install the packages required for the build and try again. PyPI 'psycopg2-binary' package instead.

Is psycopg2 the same as psycopg2-binary?

psycopg2-binary and psycopg2 both give us the same code that we interact with. The difference between the two is in how that code is installed in our computer.


1 Answers

Just would like to share. The following code worked for me:

env LDFLAGS='-L/usr/local/lib -L/usr/local/opt/openssl/lib -L/usr/local/opt/readline/lib' pip install psycopg2==2.5.2 

I am using macOS Sierra and psql 9.6.1.

I got the lib path from the pg_config command.

like image 54
chuan Avatar answered Sep 28 '22 15:09

chuan