How do you compile Python C / C ++ extensions for different OS / versions of Python?

I noticed that several mature Python libraries have precompiled versions for most architectures (Win32 / Win-amd64 / MacOS) and Python versions. What is the standard way to cross-compile extensions for different environments? Wine? Virtual machines? Looking for the crowd?

+8
python cross-platform packaging python-c-extension
source share
3 answers

We use virtual machines and a Hudson server.

We have a virtual machine for each architecture we support (usually compilation does not stretch the resources allocated to it, so the virtual machine is fine). I think that the configuration of each virtual machine can be controlled by something like Puppet or Chef to provide its suitable build environment. Of course, you can use real machines if you have the equipment, but you would like to avoid using machines that people actually use (for example, developer workstations).

Then we use a project with several configurations in Hudson to customize the build matrix. The build matrix allows us (with one click) to create several versions of python on several architectures, but theoretically you can create each and any combination that you can customize in your matrix. Of course you could use Jenkins.

+7
source share

SWIG provides a way to generate multi-platform codes.

0
source share

All my Python extension modules are C ++, not C, so I use boost Python. I also use virtual machines when I need to support different operating systems. Boost bjam build allows you to create different versions of g ++ and others with different versions of Python (2.6, 2.7). If I had an extension module that was very popular, and many people wanted to use it on platforms that I don’t have, then I would just make sure my code was very portable (it should be all the same) and provide instructions on how I create it with bjam using several different examples for different versions of Python, etc. That would be enough to start their work. If this works, you can ask them to contribute back so that others can use them (of course, not supported by you).

0
source share

All Articles