tobgu / pyrsistent

Persistent/Immutable/Functional data structures for Python
MIT License
2.03k stars 147 forks source link

Python 3.12: ModuleNotFoundError: No module named 'setuptools' #279

Closed hugovk closed 1 year ago

hugovk commented 1 year ago

The second Python 3.12 release candidate is out! :rocket:

Call to action

We strongly encourage maintainers of third-party Python projects to prepare their projects for 3.12 compatibilities during this phase, and where necessary publish Python 3.12 wheels on PyPI to be ready for the final release of 3.12.0.

Python 3.12.0 final will be released in 3 weeks: https://peps.python.org/pep-0693/

See also https://dev.to/hugovk/help-test-python-312-beta-1508/


However, when adding 3.12 to tox.ini, it fails with:

❯ tox -e py312
.pkg: install_requires> python -I -m pip install 'setuptools>=42' wheel
.pkg: _optional_hooks> python /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/pyproject_api/_backend.py True setuptools.build_meta
.pkg: get_requires_for_build_sdist> python /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/pyproject_api/_backend.py True setuptools.build_meta
.pkg: get_requires_for_build_wheel> python /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/pyproject_api/_backend.py True setuptools.build_meta
.pkg: install_requires_for_build_wheel> python -I -m pip install wheel
.pkg: prepare_metadata_for_build_wheel> python /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/pyproject_api/_backend.py True setuptools.build_meta
.pkg: build_sdist> python /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/pyproject_api/_backend.py True setuptools.build_meta
py312: install_package> python -I -m pip install --force-reinstall --no-deps /private/tmp/pyrsistent/.tox/.tmp/package/1/pyrsistent-0.19.3.tar.gz
py312: commands[0]> python /private/tmp/pyrsistent/setup.py test
Traceback (most recent call last):
  File "/private/tmp/pyrsistent/setup.py", line 2, in <module>
    from setuptools import setup, Extension
ModuleNotFoundError: No module named 'setuptools'
py312: exit 1 (0.02 seconds) /private/tmp/pyrsistent> python /private/tmp/pyrsistent/setup.py test pid=69264
.pkg: _exit> python /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/pyproject_api/_backend.py True setuptools.build_meta
  py312: FAIL code 1 (8.58=setup[8.57]+cmd[0.02] seconds)
  evaluation failed :( (8.68 seconds)

This will be due to the setuptools changes in Python 3.12:

easy_install, pkg_resources, setuptools and distutils are no longer provided by default in environments created with venv or bootstrapped with ensurepip, since they are part of the setuptools package. For projects relying on these at runtime, the setuptools project should be declared as a dependency and installed separately (typically, using pip).

https://docs.python.org/3.12/whatsnew/3.12.html#ensurepip

See also https://github.com/gitpython-developers/GitPython/issues/1640#issuecomment-1712918426 for more advice.

tobgu commented 1 year ago

setuptools is now installed as part of the test requirements and tests pass on 3.12.