Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

setuptools 60: "No module named 'setuptools'" when installing Poetry from source #2980

Closed
1 task done
alkasm opened this issue Dec 20, 2021 · 24 comments
Closed
1 task done

Comments

@alkasm
Copy link

alkasm commented Dec 20, 2021

setuptools version

60.0.0

Python version

3.9.6

OS

macOS 11.5.2

Additional environment information

No response

Description

Installing a package which uses a Poetry backend from source fails on 60.0.0. Poetry packages that I've tried (my own, as well as Poetry itself) fail to install. Package installs are successful after reverting to previous setuptools versions.

The changelog states that v60.0.0 introduces a breaking change:

#2896: Setuptools once again makes its local copy of distutils the default. To override, set SETUPTOOLS_USE_DISTUTILS=stdlib.

When using the environment variable as suggested, the package installs are again successful.

I tried a few flit and setuptools projects and observed no issues with those.

Expected behavior

The package should install without error.

How to Reproduce

Poetry itself uses poetry as a build tool, so installing poetry from source fails.

pip install --upgrade pip setuptools==60.0.0
unset SETUPTOOLS_USE_DISTUTILS
pip install git+ssh://[email protected]/python-poetry/poetry

Alternatively, clone poetry and run pip install . locally inside the repo.

Output

pip install git+ssh://[email protected]/python-poetry/poetry
pip install git+ssh://[email protected]/python-poetry/poetry
Collecting git+ssh://****@github.com/python-poetry/poetry
  Cloning ssh://****@github.com/python-poetry/poetry to /private/var/folders/k6/2dzjkwsd1mj8m52xz1b2swym0000gp/T/pip-req-build-oq1rbxm7
  Running command git clone --filter=blob:none -q 'ssh://****@github.com/python-poetry/poetry' /private/var/folders/k6/2dzjkwsd1mj8m52xz1b2swym0000gp/T/pip-req-build-oq1rbxm7
  Resolved ssh://****@github.com/python-poetry/poetry to commit 6a35cc41e950d4ff0f1efad649c1d15d689a9ce2
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
ERROR: Exception:
Traceback (most recent call last):
  File "/Users/alkasm/prog/setuptools-60.0.0-install-error/venv/lib/python3.9/site-packages/pip/_internal/cli/base_command.py", line 164, in exc_logging_wrapper
    status = run_func(*args)
  File "/Users/alkasm/prog/setuptools-60.0.0-install-error/venv/lib/python3.9/site-packages/pip/_internal/cli/req_command.py", line 205, in wrapper
    return func(self, options, args)
  File "/Users/alkasm/prog/setuptools-60.0.0-install-error/venv/lib/python3.9/site-packages/pip/_internal/commands/install.py", line 338, in run
    requirement_set = resolver.resolve(
  File "/Users/alkasm/prog/setuptools-60.0.0-install-error/venv/lib/python3.9/site-packages/pip/_internal/resolution/resolvelib/resolver.py", line 73, in resolve
    collected = self.factory.collect_root_requirements(root_reqs)
  File "/Users/alkasm/prog/setuptools-60.0.0-install-error/venv/lib/python3.9/site-packages/pip/_internal/resolution/resolvelib/factory.py", line 468, in collect_root_requirements
    req = self._make_requirement_from_install_req(
  File "/Users/alkasm/prog/setuptools-60.0.0-install-error/venv/lib/python3.9/site-packages/pip/_internal/resolution/resolvelib/factory.py", line 430, in _make_requirement_from_install_req
    cand = self._make_candidate_from_link(
  File "/Users/alkasm/prog/setuptools-60.0.0-install-error/venv/lib/python3.9/site-packages/pip/_internal/resolution/resolvelib/factory.py", line 201, in _make_candidate_from_link
    self._link_candidate_cache[link] = LinkCandidate(
  File "/Users/alkasm/prog/setuptools-60.0.0-install-error/venv/lib/python3.9/site-packages/pip/_internal/resolution/resolvelib/candidates.py", line 281, in __init__
    super().__init__(
  File "/Users/alkasm/prog/setuptools-60.0.0-install-error/venv/lib/python3.9/site-packages/pip/_internal/resolution/resolvelib/candidates.py", line 156, in __init__
    self.dist = self._prepare()
  File "/Users/alkasm/prog/setuptools-60.0.0-install-error/venv/lib/python3.9/site-packages/pip/_internal/resolution/resolvelib/candidates.py", line 225, in _prepare
    dist = self._prepare_distribution()
  File "/Users/alkasm/prog/setuptools-60.0.0-install-error/venv/lib/python3.9/site-packages/pip/_internal/resolution/resolvelib/candidates.py", line 292, in _prepare_distribution
    return preparer.prepare_linked_requirement(self._ireq, parallel_builds=True)
  File "/Users/alkasm/prog/setuptools-60.0.0-install-error/venv/lib/python3.9/site-packages/pip/_internal/operations/prepare.py", line 482, in prepare_linked_requirement
    return self._prepare_linked_requirement(req, parallel_builds)
  File "/Users/alkasm/prog/setuptools-60.0.0-install-error/venv/lib/python3.9/site-packages/pip/_internal/operations/prepare.py", line 546, in _prepare_linked_requirement
    dist = _get_prepared_distribution(
  File "/Users/alkasm/prog/setuptools-60.0.0-install-error/venv/lib/python3.9/site-packages/pip/_internal/operations/prepare.py", line 58, in _get_prepared_distribution
    abstract_dist.prepare_distribution_metadata(finder, build_isolation)
  File "/Users/alkasm/prog/setuptools-60.0.0-install-error/venv/lib/python3.9/site-packages/pip/_internal/distributions/sdist.py", line 47, in prepare_distribution_metadata
    self._install_build_reqs(finder)
  File "/Users/alkasm/prog/setuptools-60.0.0-install-error/venv/lib/python3.9/site-packages/pip/_internal/distributions/sdist.py", line 106, in _install_build_reqs
    build_reqs = self._get_build_requires_wheel()
  File "/Users/alkasm/prog/setuptools-60.0.0-install-error/venv/lib/python3.9/site-packages/pip/_internal/distributions/sdist.py", line 83, in _get_build_requires_wheel
    return backend.get_requires_for_build_wheel()
  File "/Users/alkasm/prog/setuptools-60.0.0-install-error/venv/lib/python3.9/site-packages/pip/_vendor/pep517/wrappers.py", line 172, in get_requires_for_build_wheel
    return self._call_hook('get_requires_for_build_wheel', {
  File "/Users/alkasm/prog/setuptools-60.0.0-install-error/venv/lib/python3.9/site-packages/pip/_vendor/pep517/wrappers.py", line 332, in _call_hook
    raise BackendUnavailable(data.get('traceback', ''))
pip._vendor.pep517.wrappers.BackendUnavailable: Traceback (most recent call last):
  File "/Users/alkasm/prog/setuptools-60.0.0-install-error/venv/lib/python3.9/site-packages/pip/_vendor/pep517/in_process/_in_process.py", line 89, in _build_backend
    obj = import_module(mod_path)
  File "/usr/local/Cellar/[email protected]/3.9.6/Frameworks/Python.framework/Versions/3.9/lib/python3.9/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 972, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
  File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 850, in exec_module
  File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
  File "/private/var/folders/k6/2dzjkwsd1mj8m52xz1b2swym0000gp/T/pip-build-env-hp7wsna4/overlay/lib/python3.9/site-packages/poetry/core/masonry/__init__.py", line 10, in <module>
    from .builder import Builder
  File "/private/var/folders/k6/2dzjkwsd1mj8m52xz1b2swym0000gp/T/pip-build-env-hp7wsna4/overlay/lib/python3.9/site-packages/poetry/core/masonry/builder.py", line 7, in <module>
    from .builders.sdist import SdistBuilder
  File "/private/var/folders/k6/2dzjkwsd1mj8m52xz1b2swym0000gp/T/pip-build-env-hp7wsna4/overlay/lib/python3.9/site-packages/poetry/core/masonry/builders/__init__.py", line 2, in <module>
    from .wheel import WheelBuilder
  File "/private/var/folders/k6/2dzjkwsd1mj8m52xz1b2swym0000gp/T/pip-build-env-hp7wsna4/overlay/lib/python3.9/site-packages/poetry/core/masonry/builders/wheel.py", line 23, in <module>
    from packaging.tags import sys_tags
  File "/private/var/folders/k6/2dzjkwsd1mj8m52xz1b2swym0000gp/T/pip-build-env-hp7wsna4/overlay/lib/python3.9/site-packages/poetry/core/_vendor/packaging/tags.py", line 7, in <module>
    import distutils.util
  File "/Users/alkasm/prog/setuptools-60.0.0-install-error/venv/lib/python3.9/site-packages/_distutils_hack/__init__.py", line 92, in create_module
    return importlib.import_module('setuptools._distutils')
  File "/usr/local/Cellar/[email protected]/3.9.6/Frameworks/Python.framework/Versions/3.9/lib/python3.9/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
ModuleNotFoundError: No module named 'setuptools'

Code of Conduct

  • I agree to follow the PSF Code of Conduct
@alkasm alkasm changed the title [BUG] ModuleNotFoundError: No module named 'setuptools' when installing a dependency which uses Poetry [BUG] ModuleNotFoundError: No module named 'setuptools' when installing a package which uses Poetry Dec 20, 2021
@alkasm alkasm changed the title [BUG] ModuleNotFoundError: No module named 'setuptools' when installing a package which uses Poetry [BUG] ModuleNotFoundError: No module named 'setuptools' when installing a package which uses Poetry from source Dec 20, 2021
@alkasm alkasm changed the title [BUG] ModuleNotFoundError: No module named 'setuptools' when installing a package which uses Poetry from source [BUG] "No module named 'setuptools'" when installing a package which uses Poetry from source Dec 20, 2021
@alkasm alkasm changed the title [BUG] "No module named 'setuptools'" when installing a package which uses Poetry from source [BUG] "No module named 'setuptools'" when installing a package which uses Poetry from source with setuptools 60.0.0 Dec 20, 2021
@jaraco
Copy link
Member

jaraco commented Dec 20, 2021

Thanks for the report. In this case, I’d like someone from the poetry project to help triage and ascertain what’s going wrong in Setuptools that’s triggering issues in poetry. I can likely help debug after I deal with another emergent issue on Ubuntu.

@carterwilliamson
Copy link

I also got this error but slightly different context, hope this helps:

  • poetry build => creates wheel (pipeline step 1)
  • pip install *.whl (pipeline step 2) <= Fails with the same error

I wouldn't expect poetry to be involved in step two as its in a fresh pipeline agent and just using pip to install the prebuilt package. That said, I guess there could be something I'm missing with the backend from poetry that's causing this issue.

@terencehonles
Copy link

I can confirm that either using SETUPTOOLS_USE_DISTUTILS=stdlib or adding build-system.requires = ["setuptools", "poetry_core>=1.0.0"] allows the package to be built and installed in the case I am dealing with. It looks like this is related to PEP-517 build system isolation and that setuptools is not actually installed in this context. I'm inclined to think this is an issue with poetry possibly for setuptools 60+, but since the ENV VAR affects things maybe that's not correct?

@rr-
Copy link

rr- commented Dec 21, 2021

Also running into this, but even with setuptools 57.4.0.

$ python3
Python 3.10.1 (main, Dec 11 2021, 17:22:55) [GCC 11.1.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import setuptools
set>>> setuptools.__version__
'57.4.0'

When trying to install a random package, I'm getting the following:

Traceback (most recent call last):
  File "/home/rr-/.local/lib/python3.10/site-packages/pip/_internal/cli/base_command.py", line 164, in exc_logging_wrapper
    status = run_func(*args)
  File "/home/rr-/.local/lib/python3.10/site-packages/pip/_internal/cli/req_command.py", line 205, in wrapper
    return func(self, options, args)
  File "/home/rr-/.local/lib/python3.10/site-packages/pip/_internal/commands/install.py", line 338, in run
    requirement_set = resolver.resolve(
  File "/home/rr-/.local/lib/python3.10/site-packages/pip/_internal/resolution/resolvelib/resolver.py", line 73, in resolve
    collected = self.factory.collect_root_requirements(root_reqs)
  File "/home/rr-/.local/lib/python3.10/site-packages/pip/_internal/resolution/resolvelib/factory.py", line 468, in collect_root_requirements
    req = self._make_requirement_from_install_req(
  File "/home/rr-/.local/lib/python3.10/site-packages/pip/_internal/resolution/resolvelib/factory.py", line 430, in _make_requirement_from_install_req
    cand = self._make_candidate_from_link(
  File "/home/rr-/.local/lib/python3.10/site-packages/pip/_internal/resolution/resolvelib/factory.py", line 201, in _make_candidate_from_link
    self._link_candidate_cache[link] = LinkCandidate(
  File "/home/rr-/.local/lib/python3.10/site-packages/pip/_internal/resolution/resolvelib/candidates.py", line 281, in __init__
    super().__init__(
  File "/home/rr-/.local/lib/python3.10/site-packages/pip/_internal/resolution/resolvelib/candidates.py", line 156, in __init__
    self.dist = self._prepare()
  File "/home/rr-/.local/lib/python3.10/site-packages/pip/_internal/resolution/resolvelib/candidates.py", line 225, in _prepare
    dist = self._prepare_distribution()
  File "/home/rr-/.local/lib/python3.10/site-packages/pip/_internal/resolution/resolvelib/candidates.py", line 292, in _prepare_distribution
    return preparer.prepare_linked_requirement(self._ireq, parallel_builds=True)
  File "/home/rr-/.local/lib/python3.10/site-packages/pip/_internal/operations/prepare.py", line 482, in prepare_linked_requirement
    return self._prepare_linked_requirement(req, parallel_builds)
  File "/home/rr-/.local/lib/python3.10/site-packages/pip/_internal/operations/prepare.py", line 546, in _prepare_linked_requirement
    dist = _get_prepared_distribution(
  File "/home/rr-/.local/lib/python3.10/site-packages/pip/_internal/operations/prepare.py", line 58, in _get_prepared_distribution
    abstract_dist.prepare_distribution_metadata(finder, build_isolation)
  File "/home/rr-/.local/lib/python3.10/site-packages/pip/_internal/distributions/sdist.py", line 47, in prepare_distribution_metadata
    self._install_build_reqs(finder)
  File "/home/rr-/.local/lib/python3.10/site-packages/pip/_internal/distributions/sdist.py", line 106, in _install_build_reqs
    build_reqs = self._get_build_requires_wheel()
  File "/home/rr-/.local/lib/python3.10/site-packages/pip/_internal/distributions/sdist.py", line 83, in _get_build_requires_wheel
    return backend.get_requires_for_build_wheel()
  File "/home/rr-/.local/lib/python3.10/site-packages/pip/_vendor/pep517/wrappers.py", line 172, in get_requires_for_build_wheel
    return self._call_hook('get_requires_for_build_wheel', {
  File "/home/rr-/.local/lib/python3.10/site-packages/pip/_vendor/pep517/wrappers.py", line 332, in _call_hook
    raise BackendUnavailable(data.get('traceback', ''))
pip._vendor.pep517.wrappers.BackendUnavailable: Traceback (most recent call last):
  File "/home/rr-/.local/lib/python3.10/site-packages/pip/_vendor/pep517/in_process/_in_process.py", line 89, in _build_backend
    obj = import_module(mod_path)
  File "/usr/lib/python3.10/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "", line 1050, in _gcd_import
  File "", line 1027, in _find_and_load
  File "", line 992, in _find_and_load_unlocked
  File "", line 241, in _call_with_frames_removed
  File "", line 1050, in _gcd_import
  File "", line 1027, in _find_and_load
  File "", line 1006, in _find_and_load_unlocked
  File "", line 688, in _load_unlocked
  File "", line 883, in exec_module
  File "", line 241, in _call_with_frames_removed
  File "/tmp/pip-build-env-sbcna1z1/overlay/lib/python3.10/site-packages/poetry/core/masonry/__init__.py", line 10, in 
    from .builder import Builder
  File "/tmp/pip-build-env-sbcna1z1/overlay/lib/python3.10/site-packages/poetry/core/masonry/builder.py", line 7, in 
    from .builders.sdist import SdistBuilder
  File "/tmp/pip-build-env-sbcna1z1/overlay/lib/python3.10/site-packages/poetry/core/masonry/builders/__init__.py", line 2, in 
    from .wheel import WheelBuilder
  File "/tmp/pip-build-env-sbcna1z1/overlay/lib/python3.10/site-packages/poetry/core/masonry/builders/wheel.py", line 23, in 
    from packaging.tags import sys_tags
  File "/tmp/pip-build-env-sbcna1z1/overlay/lib/python3.10/site-packages/poetry/core/_vendor/packaging/tags.py", line 7, in 
    import distutils.util
  File "/usr/lib/python3.10/site-packages/_distutils_hack/__init__.py", line 88, in create_module
    return importlib.import_module('setuptools._distutils')
  File "/usr/lib/python3.10/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
ModuleNotFoundError: No module named 'setuptools'

I don't know much about PEP-517 but hearing "build isolation" and seeing Poetry requiring setuptools, makes me think it's Poetry that should add this dependency to be downloaded whenever the user chooses to install a project?

@alkasm
Copy link
Author

alkasm commented Dec 21, 2021

FWIW I checked the following setuptools versions:

❌ 60.0.0
✅ 59.8.0
✅ 59.7.0
✅ 59.6.0
✅ 59.5.0
✅ 59.4.0
✅ 59.3.0

@jaraco
Copy link
Member

jaraco commented Dec 21, 2021

I notice in this stack trace:

  File "/tmp/pip-build-env-sbcna1z1/overlay/lib/python3.10/site-packages/poetry/core/_vendor/packaging/tags.py", line 7, in 
    import distutils.util
  File "/usr/lib/python3.10/site-packages/_distutils_hack/__init__.py", line 88, in create_module
    return importlib.import_module('setuptools._distutils')

That _distutils_hack is present (that's part of Setuptools), but Setuptools isn't present. It seems like that environment is somehow getting a partially-complete install. We'll want to figure out what creates that condition.

@rr-
Copy link

rr- commented Dec 21, 2021

After reinstalling the system package python3-setuptools it seems to be working fine for this particular version, 57.4.0, even without SETUPTOOLS_USE_DISTUTILS. What led to my broken environment was probably doing pip install --user . and sudo pip install . for a package that had [email protected] listed in [tool.poetry.dependencies] under the requires key (which in retrospective was terribly dumb, but I was heavily experimenting with Cython builds that sometimes insisted on producing temporary artifacts in /usr/lib/python3.10/site-packages/).

Anyway, what's interesting is that now after sorting out my mess, I cannot reproduce OP's issue even with a user installation of setuptools 60.0.0:

$ pip install --upgrade pip setuptools==60.0.0 --user

Requirement already satisfied: pip in /home/rr-/.local/lib/python3.10/site-packages (21.3.1)
Requirement already satisfied: setuptools==60.0.0 in /home/rr-/.local/lib/python3.10/site-packages (60.0.0)

$ unset SETUPTOOLS_USE_DISTUTILS

$ pip install git+ssh://[email protected]/python-poetry/poetry --user --force --upgrade
Collecting git+ssh://@github.com/python-poetry/poetry
Cloning ssh://
@github.com/python-poetry/poetry to /tmp/pip-req-build-dj5lb_2b
Running command git clone --filter=blob:none -q 'ssh://@github.com/python-poetry/poetry' /tmp/pip-req-build-dj5lb_2b
Resolved ssh://
@github.com/python-poetry/poetry to commit 6a35cc41e950d4ff0f1efad649c1d15d689a9ce2
Installing build dependencies ... done
Getting requirements to build wheel ... done
Preparing metadata (pyproject.toml) ... done
Collecting packaging<21.0,>=20.4
Using cached packaging-20.9-py2.py3-none-any.whl (40 kB)
Collecting shellingham<2.0,>=1.1
Using cached shellingham-1.4.0-py2.py3-none-any.whl (9.4 kB)
Collecting cleo<2.0.0,>=1.0.0a4
Using cached cleo-1.0.0a4-py3-none-any.whl (77 kB)
Collecting crashtest<0.4.0,>=0.3.0
Using cached crashtest-0.3.1-py3-none-any.whl (7.0 kB)
Collecting cachy<0.4.0,>=0.3.0
Using cached cachy-0.3.0-py2.py3-none-any.whl (20 kB)
Collecting cachecontrol[filecache]<0.13.0,>=0.12.9
Using cached CacheControl-0.12.10-py2.py3-none-any.whl (20 kB)
Collecting html5lib<2.0,>=1.0
Downloading html5lib-1.1-py2.py3-none-any.whl (112 kB)
|████████████████████████████████| 112 kB 2.2 MB/s
Collecting requests<3.0,>=2.18
Using cached requests-2.26.0-py2.py3-none-any.whl (62 kB)
Collecting entrypoints<0.4,>=0.3
Using cached entrypoints-0.3-py2.py3-none-any.whl (11 kB)
Collecting tomlkit<1.0.0,>=0.7.0
Downloading tomlkit-0.8.0-py3-none-any.whl (33 kB)
Collecting virtualenv
Using cached virtualenv-20.10.0-py2.py3-none-any.whl (5.6 MB)
Collecting poetry-core<2.0.0,>=1.1.0a6
Using cached poetry_core-1.1.0a6-py3-none-any.whl (421 kB)
Collecting keyring>=21.2.0
Downloading keyring-23.4.0-py3-none-any.whl (33 kB)
Collecting pexpect<5.0.0,>=4.7.0
Using cached pexpect-4.8.0-py2.py3-none-any.whl (59 kB)
Collecting requests-toolbelt<0.10.0,>=0.9.1
Using cached requests_toolbelt-0.9.1-py2.py3-none-any.whl (54 kB)
Collecting pkginfo<2.0,>=1.5
Using cached pkginfo-1.8.2-py2.py3-none-any.whl (26 kB)
Collecting msgpack>=0.5.2
Downloading msgpack-1.0.3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (323 kB)
|████████████████████████████████| 323 kB 7.6 MB/s
Collecting lockfile>=0.9
Using cached lockfile-0.12.2-py2.py3-none-any.whl (13 kB)
Collecting pylev<2.0.0,>=1.3.0
Using cached pylev-1.4.0-py2.py3-none-any.whl (6.1 kB)
Collecting six>=1.9
Using cached six-1.16.0-py2.py3-none-any.whl (11 kB)
Collecting webencodings
Downloading webencodings-0.5.1-py2.py3-none-any.whl (11 kB)
Collecting importlib-metadata>=3.6
Downloading importlib_metadata-4.10.0-py3-none-any.whl (17 kB)
Collecting SecretStorage>=3.2
Using cached SecretStorage-3.3.1-py3-none-any.whl (15 kB)
Collecting jeepney>=0.4.2
Using cached jeepney-0.7.1-py3-none-any.whl (54 kB)
Collecting pyparsing>=2.0.2
Using cached pyparsing-3.0.6-py3-none-any.whl (97 kB)
Collecting ptyprocess>=0.5
Using cached ptyprocess-0.7.0-py2.py3-none-any.whl (13 kB)
Collecting idna<4,>=2.5
Downloading idna-3.3-py3-none-any.whl (61 kB)
|████████████████████████████████| 61 kB 10.5 MB/s
Collecting charset-normalizer~=2.0.0
Downloading charset_normalizer-2.0.9-py3-none-any.whl (39 kB)
Collecting certifi>=2017.4.17
Using cached certifi-2021.10.8-py2.py3-none-any.whl (149 kB)
Collecting urllib3<1.27,>=1.21.1
Using cached urllib3-1.26.7-py2.py3-none-any.whl (138 kB)
Collecting filelock<4,>=3.2
Using cached filelock-3.4.0-py3-none-any.whl (9.8 kB)
Collecting platformdirs<3,>=2
Using cached platformdirs-2.4.0-py3-none-any.whl (14 kB)
Collecting backports.entry-points-selectable>=1.0.4
Using cached backports.entry_points_selectable-1.1.1-py2.py3-none-any.whl (6.2 kB)
Collecting distlib<1,>=0.3.1
Downloading distlib-0.3.4-py2.py3-none-any.whl (461 kB)
|████████████████████████████████| 461 kB 36.3 MB/s
Collecting zipp>=0.5
Using cached zipp-3.6.0-py3-none-any.whl (5.3 kB)
Collecting cryptography>=2.0
Downloading cryptography-36.0.1-cp36-abi3-manylinux_2_24_x86_64.whl (3.6 MB)
|████████████████████████████████| 3.6 MB 43.4 MB/s
Collecting cffi>=1.12
Downloading cffi-1.15.0-cp310-cp310-manylinux_2_12_x86_64.manylinux2010_x86_64.whl (446 kB)
|████████████████████████████████| 446 kB 61.6 MB/s
Collecting pycparser
Downloading pycparser-2.21-py2.py3-none-any.whl (118 kB)
|████████████████████████████████| 118 kB 91.9 MB/s
Building wheels for collected packages: poetry
Building wheel for poetry (pyproject.toml) ... done
Created wheel for poetry: filename=poetry-1.2.0a2-py3-none-any.whl size=193148 sha256=24659cf817acae154d011a3d169601c28e8e89c0036e4b8aa4cf4689284cd83c
Stored in directory: /tmp/pip-ephem-wheel-cache-j9e28yux/wheels/f8/c7/ad/6ae881761039a1ad4d07e1481e244d7602722094b4e0d6f2eb
Successfully built poetry
Installing collected packages: pycparser, urllib3, idna, charset-normalizer, cffi, certifi, zipp, requests, msgpack, jeepney, cryptography, webencodings, six, SecretStorage, pyparsing, pylev, ptyprocess, platformdirs, lockfile, importlib-metadata, filelock, distlib, crashtest, cachecontrol, backports.entry-points-selectable, virtualenv, tomlkit, shellingham, requests-toolbelt, poetry-core, pkginfo, pexpect, packaging, keyring, html5lib, entrypoints, cleo, cachy, poetry
Attempting uninstall: jeepney
Found existing installation: jeepney 0.7.1
Uninstalling jeepney-0.7.1:
Successfully uninstalled jeepney-0.7.1
Attempting uninstall: SecretStorage
Found existing installation: SecretStorage 3.3.1
Uninstalling SecretStorage-3.3.1:
Successfully uninstalled SecretStorage-3.3.1
Attempting uninstall: pylev
Found existing installation: pylev 1.4.0
Uninstalling pylev-1.4.0:
Successfully uninstalled pylev-1.4.0
Attempting uninstall: ptyprocess
Found existing installation: ptyprocess 0.7.0
Uninstalling ptyprocess-0.7.0:
Successfully uninstalled ptyprocess-0.7.0
Attempting uninstall: platformdirs
Found existing installation: platformdirs 2.4.0
Uninstalling platformdirs-2.4.0:
Successfully uninstalled platformdirs-2.4.0
Attempting uninstall: lockfile
Found existing installation: lockfile 0.12.2
Uninstalling lockfile-0.12.2:
Successfully uninstalled lockfile-0.12.2
Attempting uninstall: filelock
Found existing installation: filelock 3.4.0
Uninstalling filelock-3.4.0:
Successfully uninstalled filelock-3.4.0
Attempting uninstall: crashtest
Found existing installation: crashtest 0.3.1
Uninstalling crashtest-0.3.1:
Successfully uninstalled crashtest-0.3.1
Attempting uninstall: cachecontrol
Found existing installation: CacheControl 0.12.10
Uninstalling CacheControl-0.12.10:
Successfully uninstalled CacheControl-0.12.10
Attempting uninstall: backports.entry-points-selectable
Found existing installation: backports.entry-points-selectable 1.1.1
Uninstalling backports.entry-points-selectable-1.1.1:
Successfully uninstalled backports.entry-points-selectable-1.1.1
Attempting uninstall: virtualenv
Found existing installation: virtualenv 20.10.0
Uninstalling virtualenv-20.10.0:
Successfully uninstalled virtualenv-20.10.0
Attempting uninstall: tomlkit
Found existing installation: tomlkit 0.7.2
Uninstalling tomlkit-0.7.2:
Successfully uninstalled tomlkit-0.7.2
Attempting uninstall: shellingham
Found existing installation: shellingham 1.4.0
Uninstalling shellingham-1.4.0:
Successfully uninstalled shellingham-1.4.0
Attempting uninstall: requests-toolbelt
Found existing installation: requests-toolbelt 0.9.1
Uninstalling requests-toolbelt-0.9.1:
Successfully uninstalled requests-toolbelt-0.9.1
Attempting uninstall: poetry-core
Found existing installation: poetry-core 1.1.0a6
Uninstalling poetry-core-1.1.0a6:
Successfully uninstalled poetry-core-1.1.0a6
Attempting uninstall: pkginfo
Found existing installation: pkginfo 1.8.2
Uninstalling pkginfo-1.8.2:
Successfully uninstalled pkginfo-1.8.2
Attempting uninstall: pexpect
Found existing installation: pexpect 4.8.0
Uninstalling pexpect-4.8.0:
Successfully uninstalled pexpect-4.8.0
Attempting uninstall: keyring
Found existing installation: keyring 21.8.0
Uninstalling keyring-21.8.0:
Successfully uninstalled keyring-21.8.0
Attempting uninstall: entrypoints
Found existing installation: entrypoints 0.3
Uninstalling entrypoints-0.3:
Successfully uninstalled entrypoints-0.3
Attempting uninstall: cleo
Found existing installation: cleo 1.0.0a4
Uninstalling cleo-1.0.0a4:
Successfully uninstalled cleo-1.0.0a4
Attempting uninstall: cachy
Found existing installation: cachy 0.3.0
Uninstalling cachy-0.3.0:
Successfully uninstalled cachy-0.3.0
Attempting uninstall: poetry
Found existing installation: poetry 1.2.0a2
Uninstalling poetry-1.2.0a2:
Successfully uninstalled poetry-1.2.0a2
Successfully installed SecretStorage-3.3.1 backports.entry-points-selectable-1.1.1 cachecontrol-0.12.10 cachy-0.3.0 certifi-2021.10.8 cffi-1.15.0 charset-normalizer-2.0.9 cleo-1.0.0a4 crashtest-0.3.1 cryptography-36.0.1 distlib-0.3.4 entrypoints-0.3 filelock-3.4.0 html5lib-1.1 idna-3.3 importlib-metadata-4.10.0 jeepney-0.7.1 keyring-23.4.0 lockfile-0.12.2 msgpack-1.0.3 packaging-20.9 pexpect-4.8.0 pkginfo-1.8.2 platformdirs-2.4.0 poetry-1.2.0a2 poetry-core-1.1.0a6 ptyprocess-0.7.0 pycparser-2.21 pylev-1.4.0 pyparsing-3.0.6 requests-2.26.0 requests-toolbelt-0.9.1 shellingham-1.4.0 six-1.16.0 tomlkit-0.8.0 urllib3-1.26.7 virtualenv-20.10.0 webencodings-0.5.1 zipp-3.6.0

Here's how Python sees setuptools:

$ python3
Python 3.10.1 (main, Dec 11 2021, 17:22:55) [GCC 11.1.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import setuptools
>>> setuptools
<module 'setuptools' from '/home/rr-/.local/lib/python3.10/site-packages/setuptools/__init__.py'>
>>> setuptools.__version__
'60.0.0'

Here's my OS info:

$ uname -a
Linux lightning 5.15.5-arch1-1 pypa/setuptools#1 SMP PREEMPT Thu, 25 Nov 2021 22:09:33 +0000 x86_64 GNU/Linux
$ cat /etc/os-release
NAME="Arch Linux"
PRETTY_NAME="Arch Linux"
ID=arch
BUILD_ID=rolling
ANSI_COLOR="38;2;23;147;209"
HOME_URL="https://archlinux.org/"
DOCUMENTATION_URL="https://wiki.archlinux.org/"
SUPPORT_URL="https://bbs.archlinux.org/"
BUG_REPORT_URL="https://bugs.archlinux.org/"
LOGO=archlinux-logo

@layday
Copy link
Member

layday commented Dec 21, 2021

This is a bug (?) in pip's isolated env builder. I don't know what the purpose of these two lines is but the effect is that if you have setuptools 60+ installed in your environment when you invoke pip install, distutils-precedence.pth is processed and setuptools' meta path finder is loaded in the build environment. When Poetry goes to import packaging, which imports distutils, well...

Under line 123 of build_env.py, add:

                print(sys.meta_path)

Then try to build any Poetry package with -v and observe:

$ python -m pip install -v --no-clean --no-binary poetry poetry
Using pip 21.3.1 from /[...]/venvs/3.10/lib/python3.10/site-packages/pip (python 3.10)
Collecting poetry
  Downloading poetry-1.1.12.tar.gz (135 kB)
     |████████████████████████████████| 135 kB 884 kB/s
  Running command /[...]/venvs/3.10/bin/python /private/tmp/pip-standalone-pip-tx9ycwmk/__env_pip__.zip/pip install --ignore-installed --no-user --prefix /private/tmp/pip-build-env-rflj2e46/overlay --no-warn-script-location --no-binary poetry --only-binary :none: -i https://pypi.org/simple -- 'poetry-core>=1.0.0'
  Collecting poetry-core>=1.0.0
    Using cached poetry_core-1.0.7-py2.py3-none-any.whl (424 kB)
  Installing collected packages: poetry-core
  Successfully installed poetry-core-1.0.7
  Installing build dependencies ... done
  Running command /[...]/venvs/3.10/bin/python /[...]/venvs/3.10/lib/python3.10/site-packages/pip/_vendor/pep517/in_process/_in_process.py get_requires_for_build_wheel /tmp/tmpzseinyyz
  [<_distutils_hack.DistutilsMetaFinder object at 0x106266710>, <_distutils_hack.DistutilsMetaFinder object at 0x106266710>, <_distutils_hack.DistutilsMetaFinder object at 0x106266710>, <class '_frozen_importlib.BuiltinImporter'>, <class '_frozen_importlib.FrozenImporter'>, <class '_frozen_importlib_external.PathFinder'>]
  Getting requirements to build wheel ... done
[...]
ModuleNotFoundError: No module named 'setuptools'

@layday
Copy link
Member

layday commented Dec 21, 2021

I've also no idea why the finder is added to the meta path three times...

@alkasm
Copy link
Author

alkasm commented Dec 22, 2021

This is a bug (?) in pip's isolated env builder.

Should this be filed on pypa/pip then?

@layday
Copy link
Member

layday commented Dec 22, 2021

I think so, yeah.

@dwyatte
Copy link

dwyatte commented Dec 22, 2021

Should this be filed on pypa/pip then?

Seems they are aware of something related: pypa/pip#10742

@jaraco jaraco changed the title [BUG] "No module named 'setuptools'" when installing a package which uses Poetry from source with setuptools 60.0.0 [BUG] "No module named 'setuptools'" when installing Poetry from source with setuptools 60.0.0 Dec 22, 2021
@jaraco
Copy link
Member

jaraco commented Dec 22, 2021

Before I transfer this issue to pip, I want to be careful to understand that there's not something that Setuptools could/should be doing differently.

Under line 123 of build_env.py, add:

Where is build_env?

I'm confused. Is the issue when installing Poetry from source or when installing a package which uses Poetry from source? I see conflicting reports above?

Moreover, I'm unable to replicate the issue.

~ $ pip-run -q setuptools==60.0.4 -- -m pip-run --no-deps git+https://github.com/python-poetry/poetry -- -c pass
Collecting git+https://github.com/python-poetry/poetry
  Cloning https://github.com/python-poetry/poetry to /private/var/folders/c6/v7hnmq453xb6p2dbz1gqc6rr0000gn/T/pip-req-build-aruox4c6
  Running command git clone --filter=blob:none -q https://github.com/python-poetry/poetry /private/var/folders/c6/v7hnmq453xb6p2dbz1gqc6rr0000gn/T/pip-req-build-aruox4c6
  Resolved https://github.com/python-poetry/poetry to commit 6a35cc41e950d4ff0f1efad649c1d15d689a9ce2
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Preparing metadata (pyproject.toml) ... done
Building wheels for collected packages: poetry
  Building wheel for poetry (pyproject.toml) ... done
  Created wheel for poetry: filename=poetry-1.2.0a2-py3-none-any.whl size=193148 sha256=24659cf817acae154d011a3d169601c28e8e89c0036e4b8aa4cf4689284cd83c
  Stored in directory: /private/var/folders/c6/v7hnmq453xb6p2dbz1gqc6rr0000gn/T/pip-ephem-wheel-cache-ip3h1nnm/wheels/29/d6/da/80504347d4a909be7988b906db9e6e10d27d4a3b111dc98fc1
Successfully built poetry
Installing collected packages: poetry
Successfully installed poetry-1.2.0a2

What are the conditions needed to replicate the error?

Should this be filed on pypa/pip then?

I can transfer the issue if appropriate.

Seems they are aware of something related: pypa/pip#10742

I'm not sure that's related. The error message is different and that issue pertains to pip's internal tests and not a user-facing issue.

@jaraco jaraco changed the title [BUG] "No module named 'setuptools'" when installing Poetry from source with setuptools 60.0.0 [BUG] "No module named 'setuptools'" when installing Poetry from source with setuptools 60 Dec 22, 2021
@layday
Copy link
Member

layday commented Dec 22, 2021

Where is build_env?

build_env is the pip module I linked which is responsible for isolated builds in pip.

I'm confused. Is the issue when installing Poetry from source or when installing a package which uses Poetry from source? I see conflicting reports above?

Any Poetry package from source including Poetry itself.

What are the conditions needed to replicate the error?

python -m venv venv
venv/bin/python -m pip install -U pip setuptools
venv/bin/python -m pip install --no-binary poetry poetry

@jaraco
Copy link
Member

jaraco commented Dec 22, 2021

Moreover, I'm unable to replicate the issue.

I observe that using pip-run to attempt to reproduce was probably a mistake, because pip-run uses a sitecustomize module to ensure .pth file handling, so may interact differently with the build_env. Additionally, it sets PYTHONPATH, which may additionally violate pip's isolation expectations.

Thanks for the venv repro. That does replicate the error for me as well. And I can confirm layday's analysis in https://github.com/pypa/setuptools/issues/2939#issuecomment-999040464.

Moreover, I find if I add print(sys.meta_path) earlier in the generated sitecustomize.py file, there are already two DistutilsMetaFinders in sys.meta_path when sitecustomize is invoked. The third is added in the lines layday found. The two entries get added when site.py is processed:

$ venv/bin/python -c "import sys; print(sys.meta_path[:3])"
[<_distutils_hack.DistutilsMetaFinder object at 0x10fb222c0>, <_distutils_hack.DistutilsMetaFinder object at 0x10fb222c0>, <class '_frozen_importlib.BuiltinImporter'>]
draft $ venv/bin/python -S -c "import sys; print(sys.meta_path[:1])"
[<class '_frozen_importlib.BuiltinImporter'>]

At this point, I do agree that the issue exists primarily with pip's isolation technique... although there may need to be some setuptools support needed to honor pip's intentions.

@jaraco jaraco transferred this issue from another repository Dec 22, 2021
@jaraco
Copy link
Member

jaraco commented Dec 22, 2021

The reason the hook appears twice from site.py is because Python adds site-packages twice, causing .pth files to be processed twice:

draft $ venv/bin/python -vvv -c pass 2>&1 | grep directory
Adding directory: '/Users/jaraco/draft/venv/lib/python3.10/site-packages'
Adding directory: '/Users/jaraco/draft/venv/lib/python3.10/site-packages'

In particular, in a venv, addsitepackages is called twice apparently to give site-packages precedence over user packages.

@pradyunsg pradyunsg changed the title Dec 23, 2021
@pradyunsg
Copy link
Member

With setuptools 60.0.4:

❯ pip install git+ssh://[email protected]/python-poetry/poetry
Collecting git+ssh://****@github.com/python-poetry/poetry
  Cloning ssh://****@github.com/python-poetry/poetry to /private/var/folders/y1/j465wvf92vs938kmgqh63bj80000gn/T/pip-req-build-jo2iq4ih
  Running command git clone --filter=blob:none -q 'ssh://****@github.com/python-poetry/poetry' /private/var/folders/y1/j465wvf92vs938kmgqh63bj80000gn/T/pip-req-build-jo2iq4ih
  Resolved ssh://****@github.com/python-poetry/poetry to commit 6a35cc41e950d4ff0f1efad649c1d15d689a9ce2
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
ERROR: Exception:
Traceback (most recent call last):
  File "/Users/pradyunsg/Developer/sphinx-basic-ng/.venv/lib/python3.9/site-packages/pip/_internal/cli/base_command.py", line 164, in exc_logging_wrapper
    status = run_func(*args)
  File "/Users/pradyunsg/Developer/sphinx-basic-ng/.venv/lib/python3.9/site-packages/pip/_internal/cli/req_command.py", line 205, in wrapper
    return func(self, options, args)
  File "/Users/pradyunsg/Developer/sphinx-basic-ng/.venv/lib/python3.9/site-packages/pip/_internal/commands/install.py", line 338, in run
    requirement_set = resolver.resolve(
  File "/Users/pradyunsg/Developer/sphinx-basic-ng/.venv/lib/python3.9/site-packages/pip/_internal/resolution/resolvelib/resolver.py", line 73, in resolve
    collected = self.factory.collect_root_requirements(root_reqs)
  File "/Users/pradyunsg/Developer/sphinx-basic-ng/.venv/lib/python3.9/site-packages/pip/_internal/resolution/resolvelib/factory.py", line 468, in collect_root_requirements
    req = self._make_requirement_from_install_req(
  File "/Users/pradyunsg/Developer/sphinx-basic-ng/.venv/lib/python3.9/site-packages/pip/_internal/resolution/resolvelib/factory.py", line 430, in _make_requirement_from_install_req
    cand = self._make_candidate_from_link(
  File "/Users/pradyunsg/Developer/sphinx-basic-ng/.venv/lib/python3.9/site-packages/pip/_internal/resolution/resolvelib/factory.py", line 201, in _make_candidate_from_link
    self._link_candidate_cache[link] = LinkCandidate(
  File "/Users/pradyunsg/Developer/sphinx-basic-ng/.venv/lib/python3.9/site-packages/pip/_internal/resolution/resolvelib/candidates.py", line 281, in __init__
    super().__init__(
  File "/Users/pradyunsg/Developer/sphinx-basic-ng/.venv/lib/python3.9/site-packages/pip/_internal/resolution/resolvelib/candidates.py", line 156, in __init__
    self.dist = self._prepare()
  File "/Users/pradyunsg/Developer/sphinx-basic-ng/.venv/lib/python3.9/site-packages/pip/_internal/resolution/resolvelib/candidates.py", line 225, in _prepare
    dist = self._prepare_distribution()
  File "/Users/pradyunsg/Developer/sphinx-basic-ng/.venv/lib/python3.9/site-packages/pip/_internal/resolution/resolvelib/candidates.py", line 292, in _prepare_distribution
    return preparer.prepare_linked_requirement(self._ireq, parallel_builds=True)
  File "/Users/pradyunsg/Developer/sphinx-basic-ng/.venv/lib/python3.9/site-packages/pip/_internal/operations/prepare.py", line 482, in prepare_linked_requirement
    return self._prepare_linked_requirement(req, parallel_builds)
  File "/Users/pradyunsg/Developer/sphinx-basic-ng/.venv/lib/python3.9/site-packages/pip/_internal/operations/prepare.py", line 546, in _prepare_linked_requirement
    dist = _get_prepared_distribution(
  File "/Users/pradyunsg/Developer/sphinx-basic-ng/.venv/lib/python3.9/site-packages/pip/_internal/operations/prepare.py", line 58, in _get_prepared_distribution
    abstract_dist.prepare_distribution_metadata(finder, build_isolation)
  File "/Users/pradyunsg/Developer/sphinx-basic-ng/.venv/lib/python3.9/site-packages/pip/_internal/distributions/sdist.py", line 47, in prepare_distribution_metadata
    self._install_build_reqs(finder)
  File "/Users/pradyunsg/Developer/sphinx-basic-ng/.venv/lib/python3.9/site-packages/pip/_internal/distributions/sdist.py", line 106, in _install_build_reqs
    build_reqs = self._get_build_requires_wheel()
  File "/Users/pradyunsg/Developer/sphinx-basic-ng/.venv/lib/python3.9/site-packages/pip/_internal/distributions/sdist.py", line 83, in _get_build_requires_wheel
    return backend.get_requires_for_build_wheel()
  File "/Users/pradyunsg/Developer/sphinx-basic-ng/.venv/lib/python3.9/site-packages/pip/_vendor/pep517/wrappers.py", line 172, in get_requires_for_build_wheel
    return self._call_hook('get_requires_for_build_wheel', {
  File "/Users/pradyunsg/Developer/sphinx-basic-ng/.venv/lib/python3.9/site-packages/pip/_vendor/pep517/wrappers.py", line 332, in _call_hook
    raise BackendUnavailable(data.get('traceback', ''))
pip._vendor.pep517.wrappers.BackendUnavailable: Traceback (most recent call last):
  File "/Users/pradyunsg/Developer/sphinx-basic-ng/.venv/lib/python3.9/site-packages/pip/_vendor/pep517/in_process/_in_process.py", line 89, in _build_backend
    obj = import_module(mod_path)
  File "/opt/homebrew/Cellar/[email protected]/3.9.9/Frameworks/Python.framework/Versions/3.9/lib/python3.9/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 972, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
  File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 850, in exec_module
  File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
  File "/private/var/folders/y1/j465wvf92vs938kmgqh63bj80000gn/T/pip-build-env-3yd07mfg/overlay/lib/python3.9/site-packages/poetry/core/masonry/__init__.py", line 10, in <module>
    from .builder import Builder
  File "/private/var/folders/y1/j465wvf92vs938kmgqh63bj80000gn/T/pip-build-env-3yd07mfg/overlay/lib/python3.9/site-packages/poetry/core/masonry/builder.py", line 7, in <module>
    from .builders.sdist import SdistBuilder
  File "/private/var/folders/y1/j465wvf92vs938kmgqh63bj80000gn/T/pip-build-env-3yd07mfg/overlay/lib/python3.9/site-packages/poetry/core/masonry/builders/__init__.py", line 2, in <module>
    from .wheel import WheelBuilder
  File "/private/var/folders/y1/j465wvf92vs938kmgqh63bj80000gn/T/pip-build-env-3yd07mfg/overlay/lib/python3.9/site-packages/poetry/core/masonry/builders/wheel.py", line 23, in <module>
    from packaging.tags import sys_tags
  File "/private/var/folders/y1/j465wvf92vs938kmgqh63bj80000gn/T/pip-build-env-3yd07mfg/overlay/lib/python3.9/site-packages/poetry/core/_vendor/packaging/tags.py", line 7, in <module>
    import distutils.util
  File "/Users/pradyunsg/Developer/sphinx-basic-ng/.venv/lib/python3.9/site-packages/_distutils_hack/__init__.py", line 92, in create_module
    return importlib.import_module('setuptools._distutils')
  File "/opt/homebrew/Cellar/[email protected]/3.9.9/Frameworks/Python.framework/Versions/3.9/lib/python3.9/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
ModuleNotFoundError: No module named 'setuptools'

Hmm... It seems that _distutils_hack from the original running environment is visible inside the isolated environment. How does that hack work @jaraco?

SVAIRobotics referenced this issue in Djaizz/Djaizz Dec 24, 2021
SVAIRobotics referenced this issue in Djaizz/DjAIoT Dec 24, 2021
SVAIRobotics referenced this issue in Djaizz/Django-Query-Graph Dec 24, 2021
SVAIRobotics referenced this issue in Djaizz/Dju Dec 24, 2021
SVAIRobotics referenced this issue in FastAIAPI/FastAIAPI Dec 24, 2021
SVAIRobotics referenced this issue in Djaizz/MicroDjango Dec 24, 2021
ctn referenced this issue in h1st-ai/h1st Dec 24, 2021
This is important for user (e.g., AISE) development alongside of framework development.
@asottile
Copy link
Contributor

here's my summary of what's happening here

@pradyunsg
Copy link
Member

pradyunsg commented Dec 28, 2021

Alright, so the problem is that setuptools is using import hooks which is not something that pip's build isolation isolates against. I think the immediate fix belongs in setuptools (at best, pip can roll out a fix in Jan/Apr 2022 and this likely needs to be fixed by setuptools in a way that is compatible with older pip versions), so I'm gonna throw this back over to that repository.

I'll file a separate follow up issue on pip's end to track isolating from import hooks/pth files (likely through something like pypa/pip#10720).

@layday
Copy link
Member

layday commented Dec 28, 2021

Alright, so the problem is that setuptools is using import hooks which is not something that pip's build isolation isolates against.

As I explained 7 days ago. I understand how asottile might have missed it since he's blocked me (apparently that's a thing we do in the packaging community - just block people we disagree with), not sure how everybody else has.

@jaraco
Copy link
Member

jaraco commented Dec 28, 2021

How does that [_distutils_hack] work @jaraco?

I meant to respond to this sooner, then got distracted and it fell off my radar. The hack is pretty simple. A top-level module _distutils_hack is installed and loaded by a distutils-precedence.pth file. All that _distutils_hack.ensure_shim does is add a MetaPathFinder to find distutils inside Setuptools.

An open question to the pip team (@pradyunsg) is what are these lines intended to accomplish? Looking at the whole block, it looks like the sitecustomize explicitly adds system_site dirs in order to remove them, which has the side effect of handling .pth files on that path.

It's not obvious to me that there's anything a sitecustomize file can do to prevent the execution of the .pth hooks in system site packages, because the site packages are unconditionally added before site-customize is called. Pip will probably need to run with python -S if it wishes to suppress .pth handling in system site-packages.

I want to explore whether the MetaPathFinder should be more lenient when its accompanying module cannot be found. #2962 captures a related problem where the hook exists but picks up an unrelated setuptools module.

@jaraco
Copy link
Member

jaraco commented Dec 28, 2021

Released as 60.1.1. Please test and let me know if there are outstanding issues.

@rnickle
Copy link

rnickle commented Dec 29, 2021

Released as 60.1.1. Please test and let me know if there are outstanding issues.

I ran into this issue in one of my CI flows with poetry 1.1.12 and setuptools 60.0.0

I tried to fix it by simply applying 60.1.1, but that did not fix it. I had to additionally downgrade poetry to 1.1.11. That and this setuptools 60.1.1 fix worked for me.

@jaraco
Copy link
Member

jaraco commented Dec 29, 2021

I was worried that there was some race between fixes between poetry 1.1.12 and setuptools 60.1.1, but I'm unable to replicate the issue even with poetry 1.1.12:

draft $ venv/bin/pip install -U setuptools
Requirement already satisfied: setuptools in ./venv/lib/python3.10/site-packages (60.1.0.post20211228)
Collecting setuptools
  Downloading setuptools-60.1.1-py3-none-any.whl (952 kB)
     |████████████████████████████████| 952 kB 3.0 MB/s 
Installing collected packages: setuptools
  Attempting uninstall: setuptools
    Found existing installation: setuptools 60.1.0.post20211228
    Uninstalling setuptools-60.1.0.post20211228:
      Successfully uninstalled setuptools-60.1.0.post20211228
Successfully installed setuptools-60.1.1
WARNING: You are using pip version 21.2.3; however, version 21.3.1 is available.
You should consider upgrading via the '/Users/jaraco/draft/venv/bin/python -m pip install --upgrade pip' command.
draft $ venv/bin/pip install -v --no-clean --force-reinstall --no-binary poetry --no-deps poetry
Using pip 21.2.3 from /Users/jaraco/draft/venv/lib/python3.10/site-packages/pip (python 3.10)
Collecting poetry
  Using cached poetry-1.1.12.tar.gz (135 kB)
  Running command /Users/jaraco/draft/venv/bin/python /private/var/folders/c6/v7hnmq453xb6p2dbz1gqc6rr0000gn/T/pip-standalone-pip-pys6gzws/__env_pip__.zip/pip install --ignore-installed --no-user --prefix /private/var/folders/c6/v7hnmq453xb6p2dbz1gqc6rr0000gn/T/pip-build-env-cp7ylkg8/overlay --no-warn-script-location --no-binary poetry --only-binary :none: -i https://pypi.org/simple -- 'poetry-core>=1.0.0'
  Collecting poetry-core>=1.0.0
    Using cached poetry_core-1.0.7-py2.py3-none-any.whl (424 kB)
  Installing collected packages: poetry-core
  Successfully installed poetry-core-1.0.7
  WARNING: You are using pip version 21.2.3; however, version 21.3.1 is available.
  You should consider upgrading via the '/Users/jaraco/draft/venv/bin/python -m pip install --upgrade pip' command.
  Installing build dependencies ... done
  Running command /Users/jaraco/draft/venv/bin/python /Users/jaraco/draft/venv/lib/python3.10/site-packages/pip/_vendor/pep517/in_process/_in_process.py get_requires_for_build_wheel /var/folders/c6/v7hnmq453xb6p2dbz1gqc6rr0000gn/T/tmpxnq7m2n8
  Getting requirements to build wheel ... done
    Running command /Users/jaraco/draft/venv/bin/python /Users/jaraco/draft/venv/lib/python3.10/site-packages/pip/_vendor/pep517/in_process/_in_process.py prepare_metadata_for_build_wheel /var/folders/c6/v7hnmq453xb6p2dbz1gqc6rr0000gn/T/tmpz59by_ip
    Preparing wheel metadata ... done
Building wheels for collected packages: poetry
  Running command /Users/jaraco/draft/venv/bin/python /Users/jaraco/draft/venv/lib/python3.10/site-packages/pip/_vendor/pep517/in_process/_in_process.py build_wheel /var/folders/c6/v7hnmq453xb6p2dbz1gqc6rr0000gn/T/tmppexg7ssv
  Building wheel for poetry (PEP 517) ... done
  Created wheel for poetry: filename=poetry-1.1.12-py2.py3-none-any.whl size=175030 sha256=3d4dc5d4c7171fb251b32e49a98cecbe2795d5e681ecee2297e2b2d2ccd671fc
  Stored in directory: /Users/jaraco/Library/Caches/pip/wheels/ef/8f/20/5291aa91f96e4d6f87a0de0eb1169d19ee1c6a7f61eeb9068f
Successfully built poetry
Installing collected packages: poetry
  Attempting uninstall: poetry
    Found existing installation: poetry 1.1.12
    Uninstalling poetry-1.1.12:
      Removing file or directory /Users/jaraco/draft/venv/bin/poetry
      Removing file or directory /Users/jaraco/draft/venv/lib/python3.10/site-packages/poetry-1.1.12.dist-info/
      Removing file or directory /Users/jaraco/draft/venv/lib/python3.10/site-packages/poetry/__init__.py
      Removing file or directory /Users/jaraco/draft/venv/lib/python3.10/site-packages/poetry/__main__.py
      Removing file or directory /Users/jaraco/draft/venv/lib/python3.10/site-packages/poetry/__pycache__/
      Removing file or directory /Users/jaraco/draft/venv/lib/python3.10/site-packages/poetry/__version__.py
      Removing file or directory /Users/jaraco/draft/venv/lib/python3.10/site-packages/poetry/_vendor/
      Removing file or directory /Users/jaraco/draft/venv/lib/python3.10/site-packages/poetry/config/
      Removing file or directory /Users/jaraco/draft/venv/lib/python3.10/site-packages/poetry/console/
      Removing file or directory /Users/jaraco/draft/venv/lib/python3.10/site-packages/poetry/exceptions.py
      Removing file or directory /Users/jaraco/draft/venv/lib/python3.10/site-packages/poetry/factory.py
      Removing file or directory /Users/jaraco/draft/venv/lib/python3.10/site-packages/poetry/inspection/
      Removing file or directory /Users/jaraco/draft/venv/lib/python3.10/site-packages/poetry/installation/
      Removing file or directory /Users/jaraco/draft/venv/lib/python3.10/site-packages/poetry/io/
      Removing file or directory /Users/jaraco/draft/venv/lib/python3.10/site-packages/poetry/json/
      Removing file or directory /Users/jaraco/draft/venv/lib/python3.10/site-packages/poetry/layouts/
      Removing file or directory /Users/jaraco/draft/venv/lib/python3.10/site-packages/poetry/locations.py
      Removing file or directory /Users/jaraco/draft/venv/lib/python3.10/site-packages/poetry/masonry/
      Removing file or directory /Users/jaraco/draft/venv/lib/python3.10/site-packages/poetry/mixology/
      Removing file or directory /Users/jaraco/draft/venv/lib/python3.10/site-packages/poetry/packages/
      Removing file or directory /Users/jaraco/draft/venv/lib/python3.10/site-packages/poetry/poetry.py
      Removing file or directory /Users/jaraco/draft/venv/lib/python3.10/site-packages/poetry/publishing/
      Removing file or directory /Users/jaraco/draft/venv/lib/python3.10/site-packages/poetry/puzzle/
      Removing file or directory /Users/jaraco/draft/venv/lib/python3.10/site-packages/poetry/repositories/
      Removing file or directory /Users/jaraco/draft/venv/lib/python3.10/site-packages/poetry/utils/
      Removing file or directory /Users/jaraco/draft/venv/lib/python3.10/site-packages/poetry/version/
      Successfully uninstalled poetry-1.1.12
  changing mode of /Users/jaraco/draft/venv/bin/poetry to 755
Successfully installed poetry-1.1.12
WARNING: You are using pip version 21.2.3; however, version 21.3.1 is available.
You should consider upgrading via the '/Users/jaraco/draft/venv/bin/python -m pip install --upgrade pip' command.

Can you divine some details on how to reproduce?

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

No branches or pull requests

10 participants