Skip to content

[BUG] setuptools==77.0.1 fails to import if packaging<24.2 is installed #4894

@jakelishman

Description

@jakelishman

setuptools version

77.0.1

Python version

Tested on 3.9 and 3.13

OS

macOS

Additional environment information

No response

Description

In an environment which has a manually installed version of packaging less than the implicit requirement in setuptools of 24.2, import setuptools fails while attempting to import packaging.licenses.

setuptools vendors packaging at 24.2 and does not declare a separate dependency on it with no optionals specified. If the environment already has packaging<24 installed in it, pip install -U setuptools 'packaging<24.2' (or the like) will produce what pip considers to be a valid environment, but setuptools will import a version of packaging it is incompatible with.

This can have a knock-on effect causing some packages (I haven't tracked down the full set of criteria needed) to fail with an incorrect error message, such as (pyperclip==1.9.0 is the example I saw in our CI):

 Collecting pyperclip>=1.8 (from cmd2>=1.0.0->cliff>=2.8.0->stestr>=3.2.0->qiskit-neko==0.0.1)
  Downloading pyperclip-1.9.0.tar.gz (20 kB)
  Preparing metadata (setup.py): started
  Preparing metadata (setup.py): finished with status 'error'
  error: subprocess-exited-with-error
  
  × python setup.py egg_info did not run successfully.
  │ exit code: 1
  ╰─> [1 lines of output]
      ERROR: Can not execute `setup.py` since setuptools is not available in the build environment.
      [end of output]

Actually, setuptools==77.0.1 is installed, it's packaging.licenses that fails to import (since it's pulling from the out-of-date version of packaging, not the vendored one), but the raised ModuleNotFoundError is treated by pip as being that setuptools is absent.

Expected behavior

The import should succeed.

How to Reproduce

  1. Create a new virtual environment, seeded with pip install -U setuptools 'packaging<24.2'. No error is thrown during package resolution because setuptools without an optional does not depend on packaging (due to the vendoring).
  2. Attempt to import setuptools

Output

>>> import setuptools
Traceback (most recent call last):
  File "<python-input-0>", line 1, in <module>
    import setuptools
  File "/Users/jake/tmp/setuptools-repro/venv313/lib/python3.13/site-packages/setuptools/__init__.py", line 27, in <module>
    from .dist import Distribution
  File "/Users/jake/tmp/setuptools-repro/venv313/lib/python3.13/site-packages/setuptools/dist.py", line 15, in <module>
    from packaging.licenses import canonicalize_license_expression
ModuleNotFoundError: No module named 'packaging.licenses'

Metadata

Metadata

Assignees

No one assigned

    Labels

    Needs TriageIssues that need to be evaluated for severity and status.bug

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions