无法在 virtualenv 中安装 psycopg2 “错误:stdarg.h:没有这样的文件或目录”

Posted

技术标签:

【中文标题】无法在 virtualenv 中安装 psycopg2 “错误:stdarg.h:没有这样的文件或目录”【英文标题】:Can't install psycopg2 in virtualenv "error: stdarg.h: No such file or directory" 【发布时间】:2012-05-06 20:04:33 【问题描述】:

注意:使用easy_install时也会出现同样的错误,其他安装方式...

我面临与 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? 几乎完全相同的问题,除了我使用的是 OSX Lion (10.7) 和 Python v2.7。

它似乎也与 Can't install psycopg2 with pip in virtualenv on Mac OS X 10.7 有关,但我收到了不同的错误消息。

我提出了一个新问题,因为适用于 OSX 10.6 的解决方案(例如 http://mail.python.org/pipermail/pythonmac-sig/2009-September/021617.html)对我不起作用。

我正在尝试在 Heroku (https://devcenter.heroku.com/articles/django) 上为 Django 做教程, 我在尝试安装 psycopg2 时遇到错误。这是跟踪:

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

不知道为什么找不到stdarg.h!我在网上查了很多答案,都没有用。

【问题讨论】:

【参考方案1】:

看起来您的构建环境已损坏。 stdarg.h 是核心 gcc 头文件的一部分。在我的(Fedora 16 Linux)系统上,stdarg.h 位于 /usr/lib/gcc/x86_64-redhat-linux/4.6.2/include/stdarg.h 中,并且是 gcc 包的一部分。

在 Apple 平台上,我希望它随 XCode 一起提供。猜测一下,您安装了多个编译器/工具链,并且它们的包含路径变得混乱。我建议彻底卸载 XCode 及其所有朋友,删除相关目录以摆脱掉队者,然后重新安装。

【讨论】:

【参考方案2】:

可能是您的 Xcode 安装不完整。以下帖子帮助我使其正常工作:

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

必须为 Xcode 安装“命令行工具”(按照上面 SO 答案中的说明),然后我就可以使用 virtualenv 进行 pip 安装。

【讨论】:

以上是关于无法在 virtualenv 中安装 psycopg2 “错误:stdarg.h:没有这样的文件或目录”的主要内容,如果未能解决你的问题,请参考以下文章

无法在 virtualenv 中安装 psycopg2 “错误:stdarg.h:没有这样的文件或目录”

如何在python2.7中安装MySQLdb 在virtualenv中安装

在 openSUSE 上的 Virtualenv 中安装 TensorFlow

在 virtualenv 中安装 Django:MySQL-python 错误

如何在 Pycharm Virtualenv 中安装 kivy? [复制]

在 python 中安装模块 - pip、distribute、nose、virtualenv