setuptools "Cython is required to compile .pyx" in CI
Your build calls cythonize on .pyx files but Cython is not present in the isolated build environment. Without Cython there is nothing to translate .pyx to C, so setuptools stops before any compiler runs.
What this error means
The build fails with a message that Cython is required to compile .pyx files, or ModuleNotFoundError: No module named 'Cython' from within setup.py.
error: Cython is required to compile mypkg/fast.pyx to C
# or:
ModuleNotFoundError: No module named 'Cython'Common causes
Cython missing from build-system.requires
The isolated build env only has the declared requirements. Compiling .pyx needs Cython listed there.
Shipping .pyx without pre-generated C
An sdist that contains .pyx but not the generated .c forces a Cython compile at install time, which fails if Cython is absent.
How to fix it
Add Cython to build requirements
- List
Cythonin[build-system] requires. - Call
cythonizein setup.py. - Re-run the build.
[build-system]
requires = ["setuptools", "Cython>=3.0", "wheel"]
build-backend = "setuptools.build_meta"Ship generated C in the sdist
Include the .c files so installers can compile without Cython.
python -m cython mypkg/fast.pyx
python -m build --sdistHow to prevent it
- Declare Cython in
build-system.requiresfor any.pyxproject. - Include generated C in sdists so end users do not need Cython.
- Build wheels in CI to catch a missing Cython early.