【问题标题】:How can I get python.h into my python virtualenv on Mac OSX?如何在 Mac OSX 上将 python.h 放入我的 python virtualenv?
【发布时间】:2014-08-15 00:43:44
【问题描述】:
我正在为 python 应用程序编写 C 扩展,并且需要测试特定于 python 的 C 代码。为此,我需要将 Python.h 导入到我的 C 文件中,但在我的一生中,我一直无法做到这一点。大多数教程都提出了类似 sudo apt-get python-dev 的建议,但我的系统没有 apt-get,即使有,我认为将 dev 文件放在我的 virtualenv 中会更好。
知道如何将 Python.h 放入我的 virtualenv 中吗?
【问题讨论】:
标签:
python
c
python-extensions
【解决方案1】:
设置环境变量 C_INCLUDE_PATH 以包含你的 Python 发行版的目录。
示例:
1.获取你的python发行版的include目录
find /usr/local/Cellar/ -name Python.h
这将返回如下内容:
/usr/local/Cellar//python3/3.6.3/Frameworks/Python.framework/Versions/3.6/include/python3.6m/Python.h
现在为您设置 C_INCLUDE_PATH 变量:
export C_INCLUDE_PATH="/usr/local/Cellar//python3/3.6.3/Frameworks/Python.framework/Versions/3.6/include/python3.6m/"
【解决方案2】:
假设您使用的是通过 homebrew 安装的 MacOSX 和 Python,
在terminal,你可以找到Python.h:
find /usr/local/Cellar/ -name Python.h
返回我的系统:
/usr/local/Cellar//python/2.7.6/Frameworks/Python.framework/Versions/2.7/include/python2.7/Python.h
【解决方案3】:
在终端中,
$python-config --includes