2

I need to write python interface wrappers around some C functions, which requires the Python.h header file. I want to make sure I get the correct Python.h.

I'm working in CentOS 6.6 and decided to use Python 3.4 so as to avoid using the OS's python distribution. Online sources suggest getting the correct Python.h from python34-devel , but this package is not available for Centos 6, even through the EPEL repository. Also, I was forced to compile and install python from source, and this thread seems to suggest python34-devel might not even be helpful in this case.

How do I find the right Python.h so that I can compile C libraries for my Python configuration?

thanks in advance

2
  • You should switch to Python 3.5 already, Python 3.4 is in "security-fix" mode already. Commented Aug 22, 2016 at 13:25
  • I'm all in favor of using the latest version, but the toolchain I am using is restricted to Python 3.4 Commented Aug 22, 2016 at 14:35

1 Answer 1

1

If you do things properly and make a complete installable package for your wrapper, with setup.py, then you do not even need to know the location of the includes; as your python3.4 executable would know their location.

Minimlly your setup.py could be something like

from setuptools import setup, Extension

c_ext = Extension('mypackage._mymodule.c',
                  sources = ['mypackage/_mymodule.c'],
                  )

setup(name='mypackage',
      version='1.0',
      description='...',
      long_description='...',
      packages=['mypackage']
      ext_modules=[c_ext])

Then you would store your C extension sources in mypackage/_mymodule.c, and have mypackage/__init__.py or some python modules write nice wrappers to the C extension itself (as some things are just to tedious to do it in C); minimally this would do

from mypackage._mymodule import *

Now to install this extension, you'd just execute python3.4 setup.py install and it would automatically compile your extension using whatever include directory and compile-time options are appropriate for that installation, and install it into the site-packages directory.

Sign up to request clarification or add additional context in comments.

2 Comments

I was able to replicate this and confirmed it works. Thanks!
@Max if you had any problems there, you can add a comment here so I will edit my answer appropriately.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.