我正在尝试安装 psycopg2 以便与 Django 一起使用。我正在使用 virtualenv,当我尝试安装 psycopg2 时,我收到一条错误消息:
In file included from psycopg/psycopgmodule.c:27:
./psycopg/psycopg.h:30:10: error: 'Python.h' file not found with <angled> include; use "quotes" instead
#include <Python.h>
^~~~~~~~~~
"Python.h"
In file included from psycopg/psycopgmodule.c:27:
In file included from ./psycopg/psycopg.h:30:
psycopg/Python.h:29:10: fatal error: 'structmember.h' file not found
#include <structmember.h>
^
2 errors generated.
error: command 'clang' failed with exit status 1
我在网上发现了一些帖子似乎暗示解决这个问题的方法是安装 python-dev。不幸的是,我发现它只适用于 apt-get 和 yum。据我所知,它不适用于自制软件或 macports。谁能帮我弄清楚安装失败的原因或如何获得 psycopg2?谢谢!
编辑:我正在使用 virtualenv 并使用 postgres 应用程序。我已经安装了 XCode 命令行工具。
最佳答案
原来我对问题原因的理解是错误的。这不是因为我没有 Python 头文件,而是因为我以某种方式从自制软件 python 目录中删除了它们。在 Freenode 的 Python channel 聊天后,一位用户帮助我确定了问题所在。里面只有三个文件
/usr/local/Cellar/python/2.7.10_2/Frameworks/Python.framework/Versions/2.7/include/python2.7
所以我跑了
brew uninstall python
brew install python
它重新安装了 header 并解决了问题!
关于python - 找不到在 Mac OS X 上安装 python-dev 的方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33843313/