如何在Mac OSX上将python.h放入我的python virtualenv中? [英] How can I get python.h into my python virtualenv on Mac OSX?

查看:122
本文介绍了如何在Mac OSX上将python.h放入我的python virtualenv中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为python应用程序编写C扩展,并且需要测试特定于python的C代码.为此,我需要将Python.h导入到我的C文件中,但是对于我来说,我一直无法做到这一点.大多数教程都建议使用类似sudo apt-get python-dev的方法,但是我的系统没有apt-get,即使这样做,我也认为将dev文件放在virtualenv中会更好.

I'm writing a C extension for a python application, and need to test python-specific C code. To do so I need to import Python.h into my C files, but for the life of me I haven't been able to do that. Most tutorials suggest something along the lines of sudo apt-get python-dev, but my system doesn't have apt-get, and even if it did I think it'd be better to have the dev files in my virtualenv.

有什么想法如何将Python.h集成到我的virtualenv中吗?

Any idea how to get Python.h into my virtualenv?

推荐答案

设置环境变量C_INCLUDE_PATH以包括python发行版的目录.

Set environment variable C_INCLUDE_PATH to include the directory of your python distribution.

示例: 1.获取python发行版的包含目录

Example: 1. Get include directory of your python distribution

    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变量:

Now Set you C_INCLUDE_PATH variable:

    export C_INCLUDE_PATH="/usr/local/Cellar//python3/3.6.3/Frameworks/Python.framework/Versions/3.6/include/python3.6m/"

这篇关于如何在Mac OSX上将python.h放入我的python virtualenv中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆