setuptools: ModuleNotFoundError: No module named 'setuptools._distutils'
pip install .
suddenly started failing for many packages. Since setuptools just got a new version and pip didn’t, and setuptools appears in the error, I’m guessing it’s related to setuptools 50. Apologies if this turns out to be wrong.
This can be seen in any number of repositories, such as https://github.com/dHannasch/tox-sitepackages-example.
This doesn’t appear to be quite the same as https://github.com/pypa/setuptools/issues/2352.
I don’t fully understand all the implications of https://github.com/pypa/setuptools/issues/2350, but SETUPTOOLS_USE_DISTUTILS=stdlib
has no effect on this (ditto SETUPTOOLS_USE_DISTUTILS=1
), so I think this is a separate issue.
Travis log:
$ python -m pip install .
Processing /home/travis/build/dHannasch/tox-sitepackages-example
Installing build dependencies ... \/done
Getting requirements to build wheel ... done
ERROR: Exception:
Traceback (most recent call last):
File "/home/travis/build/dHannasch/tox-sitepackages-example/py38/lib/python3.7/site-packages/pip/_internal/cli/base_command.py", line 216, in _main
status = self.run(options, args)
File "/home/travis/build/dHannasch/tox-sitepackages-example/py38/lib/python3.7/site-packages/pip/_internal/cli/req_command.py", line 182, in wrapper
return func(self, options, args)
File "/home/travis/build/dHannasch/tox-sitepackages-example/py38/lib/python3.7/site-packages/pip/_internal/commands/install.py", line 325, in run
reqs, check_supported_wheels=not options.target_dir
File "/home/travis/build/dHannasch/tox-sitepackages-example/py38/lib/python3.7/site-packages/pip/_internal/resolution/legacy/resolver.py", line 183, in resolve
discovered_reqs.extend(self._resolve_one(requirement_set, req))
File "/home/travis/build/dHannasch/tox-sitepackages-example/py38/lib/python3.7/site-packages/pip/_internal/resolution/legacy/resolver.py", line 388, in _resolve_one
abstract_dist = self._get_abstract_dist_for(req_to_install)
File "/home/travis/build/dHannasch/tox-sitepackages-example/py38/lib/python3.7/site-packages/pip/_internal/resolution/legacy/resolver.py", line 340, in _get_abstract_dist_for
abstract_dist = self.preparer.prepare_linked_requirement(req)
File "/home/travis/build/dHannasch/tox-sitepackages-example/py38/lib/python3.7/site-packages/pip/_internal/operations/prepare.py", line 483, in prepare_linked_requirement
req, self.req_tracker, self.finder, self.build_isolation,
File "/home/travis/build/dHannasch/tox-sitepackages-example/py38/lib/python3.7/site-packages/pip/_internal/operations/prepare.py", line 91, in _get_prepared_distribution
abstract_dist.prepare_distribution_metadata(finder, build_isolation)
File "/home/travis/build/dHannasch/tox-sitepackages-example/py38/lib/python3.7/site-packages/pip/_internal/distributions/sdist.py", line 38, in prepare_distribution_metadata
self._setup_isolation(finder)
File "/home/travis/build/dHannasch/tox-sitepackages-example/py38/lib/python3.7/site-packages/pip/_internal/distributions/sdist.py", line 96, in _setup_isolation
reqs = backend.get_requires_for_build_wheel()
File "/home/travis/build/dHannasch/tox-sitepackages-example/py38/lib/python3.7/site-packages/pip/_vendor/pep517/wrappers.py", line 161, in get_requires_for_build_wheel
'config_settings': config_settings
File "/home/travis/build/dHannasch/tox-sitepackages-example/py38/lib/python3.7/site-packages/pip/_vendor/pep517/wrappers.py", line 265, in _call_hook
raise BackendUnavailable(data.get('traceback', ''))
pip._vendor.pep517.wrappers.BackendUnavailable: Traceback (most recent call last):
File "/home/travis/build/dHannasch/tox-sitepackages-example/py38/lib/python3.7/site-packages/pip/_vendor/pep517/_in_process.py", line 86, in _build_backend
obj = import_module(mod_path)
File "/opt/python/3.7.1/lib/python3.7/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 728, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/opt/python/3.7.1/lib/python3.7/site-packages/setuptools/__init__.py", line 5, in <module>
import distutils.core
File "/tmp/pip-build-env-co0toouh/overlay/lib/python3.7/site-packages/_distutils_hack/__init__.py", line 82, in create_module
return importlib.import_module('._distutils', 'setuptools')
File "/opt/python/3.7.1/lib/python3.7/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
ModuleNotFoundError: No module named 'setuptools._distutils'
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 44
- Comments: 21 (5 by maintainers)
Commits related to this issue
- Resolve pypa/setuptools#2353. This commit resolves recent catastrophic upstream breakage introduced by setuptools 50.0, the newest stable release of everyone's least favourite build tool. Unrelatedly... — committed to beartype/beartype by leycec 4 years ago
- Fixing setuptools issue https://github.com/pypa/setuptools/issues/2353 [noissue] — committed to fao89/pulp_installer by fao89 4 years ago
- Work around github.com/pypa/setuptools/issues/2353 — committed to moble/quaternion by moble 4 years ago
- Resolve pypa/setuptools#2353 and pypa/pip#6264. This commit resolves recent catastrophic upstream breakage introduced by setuptools 50.0 and pip 22.2.0, the newest stable release of everyone's least ... — committed to beartype/beartype by leycec 4 years ago
- beartype 0.2.0 released. beartype 0.2.0 is probably the most significant generational leap this package will ever see throughout its doubtless glorious lifetime, adding non-trivial support for PEP 48... — committed to beartype/beartype by leycec 4 years ago
- Fully annotate the session decorator (#342) * Fully annotate the session decorator Previously the decorator would obscure the function type. * Try to get setuptools working on Travis See ht... — committed to wntrblm/nox by layday 4 years ago
- Fix pip/setuptools related issue, see https://github.com/pypa/setuptools/issues/2353 — committed to dhensen/pydantic-odm by dhensen 4 years ago
- [travis] Support for python 3.6, 3.7 and 3.8 This code aims at aligning the CI tests across the different grimoirelab components. Python 3.5 is removed as its support period has ended and Python 3.6... — committed to vchrombie/grimoirelab-perceval by vchrombie 4 years ago
- fix: exclude unwanted setuptools, rather than pinning a specific version https://github.com/pypa/setuptools/issues/2353 — committed to renovate-bot/synthtool by tseaver 4 years ago
- fix for setuptools bug; See https://github.com/pypa/setuptools/issues/2353 — committed to abilian/abilian-core by sfermigier 3 years ago
- Fix to setuptools issue. See https://github.com/pypa/setuptools/issues/2353 — committed to abilian/abilian-sbe by sfermigier 3 years ago
- [travis] Support for python 3.6, 3.7 and 3.8 This code aims at aligning the CI tests across the different grimoirelab components. Python 3.5 is removed as its support period has ended and Python 3.6... — committed to lfpratik/grimoirelab-perceval by vchrombie 4 years ago
- pybind/mgr/dashboard/run-backend-api-tests: Older setuptools https://github.com/pypa/setuptools/issues/2353 Signed-off-by: David Galloway <dgallowa@redhat.com> — committed to ceph/ceph by deleted user 3 years ago
- pybind/mgr/dashboard/run-backend-api-tests: Older setuptools https://github.com/pypa/setuptools/issues/2353 Signed-off-by: David Galloway <dgallowa@redhat.com> — committed to ceph/ceph by deleted user 3 years ago
- pybind/mgr/dashboard/run-backend-api-tests: Older setuptools https://github.com/pypa/setuptools/issues/2353 Signed-off-by: David Galloway <dgallowa@redhat.com> (cherry picked from commit 4ab2df179b0... — committed to rhcs-dashboard/ceph by deleted user 3 years ago
- Make tox test more robust with setuptools (#23) Somehow, adding tbump as a dependency made tox upset with setuptools. I regenerated the poetry.lock, and added SETUPTOOLS_USE_DISTUTILS=stdlib to th... — committed to pechersky/sendoff by pechersky 3 years ago
- Build system: Exclude broken version of setuptools Apparently, version 60.X (up including 62) introduces a bug manifesting in imports not found: ImportError: cannot import name 'build_py' from 'setu... — committed to qtproject/pyside-pyside-setup by FriedemannKleint 2 years ago
- Resolve pypa/setuptools#2353 and pypa/pip#6264. This commit resolves recent catastrophic upstream breakage introduced by setuptools 50.0 and pip 22.2.0, the newest stable release of everyone's least ... — committed to betsee/betse by leycec 4 years ago
- **BETSE 1.2.0** released. This minor release resolves a growing cacophony of compatibility issues that have accrued in the two-and-a-half years since BETSE's last prior stable release (i.e., BETSE 1.... — committed to betsee/betse by leycec 2 years ago
@shakthifuture Setting environment variable
SETUPTOOLS_USE_DISTUTILS=stdlib
is a workaround, e.g.:So, setuptools 50.0 is fundamentally broken and breaks the entire Python ecosystem – both open-source and not. Well, isn’t that special. Heads need rolling (especially those currently attached to the still-functioning torsos of managerial project leads). Until the community tastes sweet vengeance, the following is a slightly saner solution than @dHannasch’s excellent starting point:
That is to say, downstream projects should probably only blacklist the specific version of setuptools known to catastrophically fail under the fairly safe assumption that the next stable release will either hopefully revert or perhaps even correctly fix the breakage.
I can confirm the above circumvention behaves as expected in a project just maliciously blind-sided by this packaging horror show. Passing
tox
-based tests or it didn’t happen, of course.Die, setuptools 50.0! Die! 🩸
OK - I’m in no way an expert on PEP-517, but I think the bug here is in
pip
, notsetuptools
- or maybe there’s one bug in each.If a
pyproject.toml
contains something like:then
pip
installs the latest version of setuptools into a temp directory with a name like (for instance):/tmp/pip-build-env-5v90m1w9/overlay/lib/python3.8/site-packages
After it does that, it eventually calls the
get_requires_for_build_wheel
hook, in a new subprocess. In that subprocess, ifpip
was run inside avirtualenv
created with--system-site-packages
, thensys.path
is something like:The overlay directory is after the system site packages directory, which means that any build dependencies installed by
pip
because they were required by thepyproject.toml
are later in the search path than the ones that were already installed in the site-packages directory.I think there’s one bug in each here: the
_distutils_hack
probably shouldn’t do anything if there’s a differentsetuptools
ahead of it insys.path
- whicheversetuptools
is earliest in the module search path should be completely responsible for everything; a.pth
file from later in the search path shouldn’t be screwing it up. And,pip
probably shouldn’t be calling the hook in an environment where already-installed modules are taking precedence over modules specifically required by thepyproject.toml
- the whole point of an isolated build is to isolate you from what’s installed system-wide.I had same issue. Removing pyproject.toml from the library which failed to install pass through it
FYI, the AWS lambdas running Python were also broken.
https://stackoverflow.com/questions/63688774/some-aws-lambda-functions-stopped-working-with-no-module-named-setuptools-dist
Yeah, we’ve had a suspicion about the pip as well. We then tried downgrading to v18.1 and it worked here!
This Dockerfile is somewhat convoluted, but this is the simplest way I’ve found to reproduce this problem so far:
EDIT: The installation succeeds if you set
SETUPTOOLS_USE_DISTUTILS=stdlib
That’s true, and a useful workaround, but I think that’s just because with no pyproject.toml, setuptools 50 doesn’t get installed in the first place.
So anyone can avoid this problem for now by specifying setuptools<50 in their pyproject.toml, but the fact that that works probably isn’t relevant for debugging setuptools, sadly. Oh well.
E.g.
There is, in fact, an old pip issue for exactly this bug. https://github.com/pypa/pip/issues/6264#issuecomment-685230919.
I’ve been able to consistently reproduce this with a
virtualenv
created with--system-site-packages
where setuptools < 50 is installed in the system site packages directory. I filed https://github.com/pypa/virtualenv/issues/1934 for it ~because the behavior differs betweenvirtualenv
andvenv
~. Update: Scratch that, after seeing https://github.com/pypa/setuptools/issues/2353#issuecomment-685177014 I tried reproducing it withvenv
instead ofvirtualenv
again and succeeded, so it’s not in any way specific tovirtualenv
as opposed tovenv
. In any event the reproduction test case from that issue should still be useful.Clearly there is some case where an isolated build isn’t being properly isolated, and it’s managing to pick up a different
setuptools
than the one that was installed for the isolated build.