如何为多个Python版本和平台构建编译模块 [英] How to build a compiled module for multiple Python versions and platforms
问题描述
我已经为自己的进程构建了一个Python 3模块。
I have build a Python 3 module for my own process.
我使用cython编译和包装C ++源代码。
I use cython to compile and wrap C++ sources.
我有一台具有Python 3.4的Linux(Debian Jessie)计算机,因此cythonize使我成为 Processing.cpython-34m.so
并将其复制到 /usr/local/lib/python3.4/dist-packages
。
I have a Linux (Debian Jessie) machine with Python 3.4 and so cythonize make me a Processing.cpython-34m.so
and copy it to /usr/local/lib/python3.4/dist-packages
.
但是当我在具有python3.5,我必须重新编译所有内容。
But when I use it on another machine which has python3.5, I have to recompile everything.
如何从我的机器上为所有Python 3版本和多个平台构建Linux或pip软件包(在这里,仅Jessie和Stretch(可能非常接近,确实相等))?
最好不必在我的机器上安装所有版本的Python 3。
How can I build a Linux or pip package from my machine for all Python 3 version and multiple platforms (here, just Jessie and Stretch, which might be very closed indeed equal) ? Preferably without having to install all version of Python 3 on my machine.
这是我的用于cythonization的setup.py文件:
Here is my setup.py file for cythonization :
from distutils.core import setup, Extension
from Cython.Build import cythonize
setup(ext_modules = cythonize(Extension(
"MyProcessing",
sources=["MyProcessing.pyx", "myprocess.cpp", "mythirdp.cpp"],
language="c++",
)))
谢谢。
推荐答案
使 manylinux1
二进制轮在各个发行版中均有效-请参见 PEP-513
Make manylinux1
binary wheels that work across distributions - see PEP-513
它涉及在官方PyPa上运行docker构建 manylinux1
泊坞窗映像,可为所有python版本构建二进制轮子。
It involves running a docker build on the official PyPa manylinux1
docker images that builds binary wheels for all python versions.
这些轮子可以在PyPi上分发,并且可以在各个分发版中使用。
These wheels can be distributed on PyPi and are usable across distributions.
约束是,构建需要在Centos5发行版中完成,该发行版的 manylinux1
映像基于兼容性。
The constraint is that the build needs to be done in a Centos5 distribution which the manylinux1
image is based on for compatibility.
请参见 PyPa的manylinux演示存储库例如。
这篇关于如何为多个Python版本和平台构建编译模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!