How can I get python.h into my python virtualenv on Mac OSX?
Asked Answered
B

3

9

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.

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

Barramunda answered 24/6, 2014 at 16:38 Comment(0)
G
10

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

Example: 1. Get include directory of your python distribution

    find /usr/local/Cellar/ -name Python.h

This will return something like this:

    /usr/local/Cellar//python3/3.6.3/Frameworks/Python.framework/Versions/3.6/include/python3.6m/Python.h

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/"
Greenland answered 23/12, 2017 at 21:6 Comment(1)
I needed to use find /opt/homebrew/Cellar -name Python.h for macOS Ventura 13.4.1. I did not have a /usr/local/Cellar/ directory.Lauer
R
4

in terminal,

$python-config --includes
Relaxation answered 14/2, 2019 at 7:43 Comment(0)
C
3

Assuming you are using MacOSX and Python installed through homebrew,

in terminal, you can find Python.h with:

find /usr/local/Cellar/ -name Python.h

that return on my sytem:

/usr/local/Cellar//python/2.7.6/Frameworks/Python.framework/Versions/2.7/include/python2.7/Python.h
Cuprum answered 24/6, 2014 at 16:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.