Search code examples
cythonsetup.pydistutilscythonize

Publishing cython sources for linux and windows users


I would like to publish my cython lib on pypi.

I would like to simplify a lot the life of window's users by compiling sources for 64-bits architectures as well as 32-bits architecture.

So far my setup looks like this :

from distutils.core import setup
from distutils.extension import Extension
from Cython.Build import cythonize

module = Extension('*', ['package/*.pyx'])

setup(ext_modules=cythonize(module))

When I do a python setup.py sdist, I can do pip install path/to/tarball, that compiles the sources.

My question is, if I compile with a windows vm, how can I publish the project so Unix users can compile sources themself and windows users do not compile the sources but get the .pyd installed in their python path?


Solution

  • For Unix users create an sdist:

    python setup.py sdist
    

    For w32/w64 users create binary wheels:

    python setup.py bdist_wheel
    

    The wheels must be created on the same platform they will be installed; setuptools cannot do cross-platform compilation. So for w32/w64 you have to run 32- and 64-bit windows with the corresponding compilers, Python versions (binary wheels are version-dependent) and corresponding header files.