我在Mac OS 10.6.3上安装psycopg2时,它提示找不到“stdarg.h”,但我可以看到它在那里;我该怎么办?

5 投票
3 回答
1500 浏览
提问于 2025-04-15 23:59

我正在拼命尝试成功安装psycopg2,但总是遇到错误。最近一次的错误似乎是找不到“stdarg.h”这个文件(见下面的代码)。不过我亲眼看到在/Developer/SDKs/MacOSX10.4u.sdk/usr/include/stdarg.h这个地方确实有一个叫stdarg.h的文件(错误信息说找不到的地方),所以我不知道该怎么办。

我使用的是Mac OS 10.6.3,最近几天我确保更新了所有最新的操作系统开发工具。

我有Python 2.6.2和PostgreSQL 8.4,如果这有什么影响的话。

python setup.py install    
running install
running build
running build_py
running build_ext
building 'psycopg2._psycopg' extension
creating build/temp.macosx-10.3-fat-2.6
creating build/temp.macosx-10.3-fat-2.6/psycopg
gcc -arch ppc -arch i386 -isysroot /Developer/SDKs/MacOSX10.4u.sdk -fno-strict-aliasing -fno-common -dynamic -DNDEBUG -g -O3 -DPSYCOPG_DEFAULT_PYDATETIME=1 -DPSYCOPG_VERSION="2.2.1 (dt dec ext pq3)" -DPG_VERSION_HEX=0x080404 -DPSYCOPG_EXTENSIONS=1 -DPSYCOPG_NEW_BOOLEAN=1 -DHAVE_PQFREEMEM=1 -DHAVE_PQPROTOCOL3=1 -I/Library/Frameworks/Python.framework/Versions/2.6/include/python2.6 -I. -I/opt/local/include/postgresql84 -I/opt/local/include/postgresql84/server -c psycopg/psycopgmodule.c -o build/temp.macosx-10.3-fat-2.6/psycopg/psycopgmodule.o
In file included from /Library/Frameworks/Python.framework/Versions/2.6/include/python2.6/unicodeobject.h:4,
             from /Library/Frameworks/Python.framework/Versions/2.6/include/python2.6/Python.h:85,
             from psycopg/psycopgmodule.c:27:
/Developer/SDKs/MacOSX10.4u.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.6/include/python2.6/unicodeobject.h:4,
             from /Library/Frameworks/Python.framework/Versions/2.6/include/python2.6/Python.h:85,
             from psycopg/psycopgmodule.c:27:
/Developer/SDKs/MacOSX10.4u.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/folders/MQ/MQ-tWOWWG+izzuZCrAJpzk+++TI/-Tmp-//ccakFhRS.out
error: command 'gcc' failed with exit status 

3 个回答

1

我之前遇到过一个很类似的问题(不过我是用的OSX Lion和Python 2.7)无法在虚拟环境中安装psycopg2,错误:stdarg.h:没有这样的文件或目录

最后我用了这个解决方案:https://stackoverflow.com/a/8834568/396327

简单来说,就是从头开始卸载和重新安装XCode(还做了一些额外的调整,让它能识别gcc-4.2)。

3

我不知道你具体遇到了什么问题,但我建议你使用 macports 来安装它。
安装 psycopg2 非常简单:

sudo port install py26-psycopg2
3

以下步骤对我有效:

  1. $ mkvirtualenv --no-site-packages --distribute psycopg2_test
  2. $ cd $VIRTUAL_ENV
  3. $ pip install psycopg2

注意事项

  • 我通过 MacPorts 安装了基础的 Python。
  • 上面的命令使用了:

  • 我通过以下步骤安装了 pip

    1. wget http://python-distribute.org/distribute_setup.py
    2. python distribute_setup.py
    3. easy_install pip

更新:我意识到这看起来有点繁琐,但学习如何使用 virtualenv 及其相关工具是一个值得的投资,特别是在处理有很多依赖的项目时,这样的学习会很快带来回报。

撰写回答