Can't install psycopg2 in virtualenv “error: s

2019-07-27 16:39发布

问题:

NOTE: This same error also occurs when using easy_install, other ways of installation...

I'm facing almost exactly the same problem as I'm trying to install psycopg2 onto Mac OS 10.6.3; it claims it can't find "stdarg.h" but I can see it's there; what should I do? , except I'm on OSX Lion (10.7) and I'm on Python v2.7.

It's also seemingly related to Can't install psycopg2 with pip in virtualenv on Mac OS X 10.7 but I get a different error message.

I made a new question because solutions that worked for OSX 10.6 (such as http://mail.python.org/pipermail/pythonmac-sig/2009-September/021617.html) don't work for me.

I'm trying to do the tutorial for Django on Heroku (https://devcenter.heroku.com/articles/django), and I run into an error trying to install psycopg2. Here's the trace:

Downloading/unpacking psycopg2
  Running setup.py egg_info for package psycopg2

    no previously-included directories found matching 'doc/src/_build'
Installing collected packages: psycopg2
  Running setup.py install for psycopg2
    building 'psycopg2._psycopg' extension
    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.5 (dt dec pq3 ext)" -DPG_VERSION_HEX=0x090005 -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/psycopgmodule.c -o build/temp.macosx-10.6-intel-2.7/psycopg/psycopgmodule.o
    In file included from /Library/Frameworks/Python.framework/Versions/2.7/include/python2.7/unicodeobject.h:4,
                     from /Library/Frameworks/Python.framework/Versions/2.7/include/python2.7/Python.h:85,
                     from ./psycopg/psycopg.h:30,
                     from psycopg/psycopgmodule.c:27:
    /Developer/SDKs/MacOSX10.6.sdk/usr/include/stdarg.h:4:25: error: stdarg.h: No such file or directory
    In file included from /Library/Frameworks/Python.framework/Versions/2.7/include/python2.7/unicodeobject.h:4,
                     from /Library/Frameworks/Python.framework/Versions/2.7/include/python2.7/Python.h:85,
                     from ./psycopg/psycopg.h:30,
                     from psycopg/psycopgmodule.c:27:
    /Developer/SDKs/MacOSX10.6.sdk/usr/include/stdarg.h:4:25: error: stdarg.h: No such file or directory
    lipo: can't figure out the architecture type of: /var/tmp//ccHla8Gp.out
    error: command 'gcc-4.2' failed with exit status 1
    Complete output from command /Users/AndyFang/Desktop/code/venv/bin/python -c "import setuptools;__file__='/Users/AndyFang/Desktop/code/venv/build/psycopg2/setup.py';exec(compile(open(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --single-version-externally-managed --record /tmp/pip-ONvqYm-record/install-record.txt --install-headers /Users/AndyFang/Desktop/code/venv/bin/../include/site/python2.7:
    running install

running build

running build_py

running build_ext

building 'psycopg2._psycopg' extension

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.5 (dt dec pq3 ext)" -DPG_VERSION_HEX=0x090005 -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/psycopgmodule.c -o build/temp.macosx-10.6-intel-2.7/psycopg/psycopgmodule.o

In file included from /Library/Frameworks/Python.framework/Versions/2.7/include/python2.7/unicodeobject.h:4,

                 from /Library/Frameworks/Python.framework/Versions/2.7/include/python2.7/Python.h:85,

                 from ./psycopg/psycopg.h:30,

                 from psycopg/psycopgmodule.c:27:

/Developer/SDKs/MacOSX10.6.sdk/usr/include/stdarg.h:4:25: error: stdarg.h: No such file or directory

In file included from /Library/Frameworks/Python.framework/Versions/2.7/include/python2.7/unicodeobject.h:4,

                 from /Library/Frameworks/Python.framework/Versions/2.7/include/python2.7/Python.h:85,

                 from ./psycopg/psycopg.h:30,

                 from psycopg/psycopgmodule.c:27:

/Developer/SDKs/MacOSX10.6.sdk/usr/include/stdarg.h:4:25: error: stdarg.h: No such file or directory

lipo: can't figure out the architecture type of: /var/tmp//ccHla8Gp.out

error: command 'gcc-4.2' failed with exit status 1

----------------------------------------
Command /Users/AndyFang/Desktop/code/venv/bin/python -c "import setuptools;__file__='/Users/AndyFang/Desktop/code/venv/build/psycopg2/setup.py';exec(compile(open(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --single-version-externally-managed --record /tmp/pip-ONvqYm-record/install-record.txt --install-headers /Users/AndyFang/Desktop/code/venv/bin/../include/site/python2.7 failed with error code 1 in /Users/AndyFang/Desktop/code/venv/build/psycopg2
Storing complete log in /Users/AndyFang/.pip/pip.log

I don't know why it can't find stdarg.h! I've looked into a lot of answers online, to no avail.

回答1:

It looks like you have a broken build environment. stdarg.h is part of the core gcc headers. On my (Fedora 16 Linux) system stdarg.h is in /usr/lib/gcc/x86_64-redhat-linux/4.6.2/include/stdarg.h and is part of the gcc package.

On Apple platforms I expect it's shipped with XCode. At a guess, you have more than one compiler/toolchain installed, and their include paths are getting muddled. I suggest clean-uninstalling XCode and all its friends, deleting the relevant directories to get rid of stragglers, then reinstalling the lot.



回答2:

It may be that your Xcode installation is incomplete. The following post helped me get it working:

https://stackoverflow.com/a/10326004/1361851

Had to install "command line tools" for Xcode (follow directions in SO answer above) and then I was able to pip install with the virtualenv.