Skip to content

Fix "ModuleNotFoundError" for bdist_wheel on Python 3.12 - #4229

Closed
christian-krieg wants to merge 2 commits into
pypa:mainfrom
christian-krieg:fix/py312-byte_compile
Closed

christian-krieg wants to merge 2 commits into
pypa:mainfrom
christian-krieg:fix/py312-byte_compile

Conversation

@christian-krieg

@christian-krieg christian-krieg commented Feb 20, 2024 •

Copy link
Copy Markdown

Summary of changes

When running python3 setup.py bdist_wheel on Python 3.12, setuptools exits with:

writing byte-compilation script '/tmp/<tmpfilename>.py'
[...]
Traceback (most recent call last):
  File "/tmp/<tmpfilename>.py", line 1, in <module>
    from distutils.util import byte_compile
ModuleNotFoundError: No module named 'distutils'

After some research, I learned that distutils moved to setuptools (#3661).

Importing setuptools in the generated byte-compilation script solves the issue.

Closes

Pull Request Checklist

@abravalheri

Copy link
Copy Markdown
Contributor

Hi @christian-krieg thank you very much for the contribution.

Changes in the setuptools/_distutils directory need to be proposed in the https://github.com/pypa/distutils to avoid merge conflicts. Setuptools simply copies the directory from there, so any changes are likely to be overwriting once a new version of distutils is updated.

@abravalheri

Copy link
Copy Markdown
Contributor

Also please note that running python setup.py ... commands directly as if it was a CLI tool is deprecated (setup.py keeps being a perfectly valid configuration file, but setuptools no longer supports its usage as a CLI tool).

Hopefully you don't see this error when you build the project using the https://github.com/pypa/build or use pip directly.

@christian-krieg

Copy link
Copy Markdown
Author

Hi @abravalheri, python -m build --wheel perfectly solves my problem. Thank you so much for the hint, I was not aware of the new standard way of building a wheel (It may appear overwhelming to keep track of all the python packaging options, especially if you don't do it every day).

I'll close this PR then.

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.

2 participants