Skip to content

buildsystem: pull in setuptools so Cython finds distutils#1804

Closed
nickk02 wants to merge 1 commit into
SFTtech:masterfrom
nickk02:fix/cythonize-distutils
Closed

buildsystem: pull in setuptools so Cython finds distutils#1804
nickk02 wants to merge 1 commit into
SFTtech:masterfrom
nickk02:fix/cythonize-distutils

Conversation

@nickk02

@nickk02 nickk02 commented May 29, 2026

Copy link
Copy Markdown
Contributor

Merge Checklist

On Python 3.12 distutils is gone from the stdlib, but cythonize() still does from distutils.extension import Extension deep in its dependency scan, so the build dies with ModuleNotFoundError: No module named 'distutils'. setuptools ships a stand-in and installs the import shim when it's imported, but the site-startup shim isn't always active depending on how setuptools landed on the box, which is why people hit this even with setuptools installed.

cythonize.py now imports setuptools explicitly before Cython, so the shim is in place before Cython goes looking, and if setuptools genuinely isn't there it bails with an "install setuptools" message instead of a deep traceback.

Reproduced on a python without setuptools (distutils import fails); with the change cythonize.py prints the clear message, and the normal build with setuptools present runs through untouched.

Closes #1769.

@nickk02

nickk02 commented May 29, 2026

Copy link
Copy Markdown
Contributor Author

The macOS-CI failure here isn't anything in this PR: configure aborts at find_package(Eigen3 3.3) rejecting the Eigen 5 the runner ships, before the build runs. That's the issue #1801 fixes. Once #1801 lands I'll rebase this onto master and the check goes green.

@TheJJ

TheJJ commented May 31, 2026

Copy link
Copy Markdown
Member

hmm, is this really a problem currently? it seems this should be fixed in cython, i can't imagine all downstream projects need workarounds like this? :)

On Python 3.12 distutils is gone from the stdlib, but Cython's
cythonize() still does `from distutils.extension import Extension` deep
in its dependency scan, so the build dies with "No module named
'distutils'". setuptools ships a stand-in and wires up the import shim
when it's imported, but the site-startup shim isn't always active (it
depends on how setuptools landed on the box), which is why some people
hit this even with setuptools installed.

Import setuptools explicitly at the top of cythonize.py so the shim is
in place before Cython looks, and bail with a clear "install setuptools"
message instead of a deep traceback if it isn't there at all.

Closes #1769.
@nickk02 nickk02 force-pushed the fix/cythonize-distutils branch from 1df8dfa to f0ac95e Compare June 6, 2026 21:16
@nickk02 nickk02 closed this by deleting the head repository Jun 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cythonize error when building with nyan

2 participants