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

你离开我真会死。 提交于 2021-02-07 06:16:05

问题


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


回答1:


We use Virtual Machines and a Hudson server.

We have a Virtual Machine for each architecture we support (generally compiling doesn't stretch the resources allocated to them, so a VM is fine). I guess the configuration of each VM could be managed by something like Puppet or Chef to ensure it is a suitable build environment. You could of course use real machines if you have the hardware, but you'd want to avoid using machines which people are actually using (e.g. developer workstations).

We then use a multi-configuration project in Hudson to setup a build matrix. The build matrix allows us to (with a single click) build multiple python versions, on multiple architectures, but in theory you can build every and any combination you can setup in your matrix. Of course you could use Jenkins instead.




回答2:


SWIG provides a path for multiplatform code generation.




回答3:


All of 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's bjam build driver allows you to build with different versions of Python (2.6, 2.7) different versions of g++ and various other things. If I had an extension module that was very popular and many people wanted to use it on platforms that I do not have, then I would just make sure my code was very portable (it should be anyway) and provide instructions on how I build it with bjam using several different examples for different Python versions, etc. That would be enough to get them started. If this works, you could ask them to contribute their builds back so others could use them (unsupported by you of course).



来源:https://stackoverflow.com/questions/8721918/how-do-you-compile-python-c-c-extensions-for-different-os-versions-of-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!