Skip to content

Setuptools should not rely on pkg_resources #3085

Description

@jaraco

This issue basically tracks the root goal of obviating pkg_resources, in particular that Setuptools depends on it.

Over the past few years, myself and others have worked hard to create importlib.resources and importlib.metadata in the goal of superseding pkg_resources. These libraries are now very stable and replacing much of the functionality provided by pkg_resources.

In python/importlib_metadata#38, I examined the setuptools package to determine its level of dependency on pkg_resources. Unsurprisingly, there is a diverse set of interfaces on which setuptools relies.

Nevertheless, this project should work toward Setuptools adopting the importlib features in place of pkg_resources.

Activity

  1. romuald commented on Feb 14, 2022

    @romuald

    This somehow breaks projects entry points to pyramid/paste it seems, which aren't able to find their entry point anymore (I have no idea what's the cause)

    Error for Google:

    LookupError: Entry point 'main' not found in egg 'my.package' (dir: xxx/.pyenv-python3.7/lib/python3.7/site-packages; protocols: paste.app_factory, paste.composite_factory, paste.composit_factory; entry_points: )

  2. armanckeser commented on Feb 14, 2022

    @armanckeser

    The same pr causes this issue I think #3102

  3. jaraco commented on May 20, 2025

    @jaraco
    MemberAuthor

    Now that the setuptools code base no longer depends on pkg_resources, I'm considering once again republishing pkg_resources as a separate package.

    I've reactivated the pypa/pkg_resources repo and re-run a filter operation on this repo to re-capture the history of that code there:

    git filter-repo --path pkg_resources/ --path api_tests.txt --path pkg_resources.py --path pkg_resources.txt --path setuptools/tests/test_resources.py tests/api_tests.txt tests/test_pkg_resources.py
    

    I'm now pondering publishing that code to see if the setuptools tests can continue to run by requiring that package at test time.

  4. jaraco commented on May 21, 2025

    @jaraco
    MemberAuthor

    Attempting to remove pkg_resources, the pbr tests fail with this traceback:

      File "/Users/jaraco/draft/.venv/lib/python3.13/site-packages/pbr/core.py", line 53, in <module>
        from pbr import util
      File "/Users/jaraco/draft/.venv/lib/python3.13/site-packages/pbr/util.py", line 75, in <module>
        import pkg_resources
    ModuleNotFoundError: No module named 'pkg_resources'
    

    It seems that pbr is reliant on the interface.

  5. jaraco commented on May 21, 2025

    @jaraco
    MemberAuthor

    pbr uses pkg_resources in exactly one place, to evaluate markers. That's definitely a deprecated use and superseded by 'importlib.metadata' and 'packaging'.

  6. jaraco commented on May 21, 2025

    @jaraco
    MemberAuthor

    I tried uploading a copy of pkg_resources to PyPI, but it seems that name is blocked:

     pkg_resources main 🐚 twine upload dist/*
    Uploading distributions to https://upload.pypi.org/legacy/
    Uploading pkg_resources-1.0.0-py3-none-any.whl
    100% ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 45.0/45.0 kB • 00:00 • 346.9 MB/s
    WARNING  Error during upload. Retry with the --verbose option for more details.                                                                          
    ERROR    HTTPError: 403 Forbidden from https://upload.pypi.org/legacy/                                                                                   
             The user 'jaraco' isn't allowed to upload to project 'pkg-resources'. See https://pypi.org/help/#project-name for more information.             
    

    I don't think it's worth trying to reclaim that name, so I'm going to assume that supplying a separate pkg_resources package to supplement setuptools without pkg_resources. Environments that rely on setuptools will simply have to install setuptools<81.

  7. abravalheri commented on May 23, 2025

    @abravalheri
    Contributor

    I don't think it's worth trying to reclaim that name, so I'm going to assume that supplying a separate pkg_resources package to supplement setuptools without pkg_resources. Environments that rely on setuptools will simply have to install setuptools<81.

    It is a bit unfortunate that we cannot publish to PyPI. I can see a couple of situations in which it would be useful. If we want to be very conservative and try to reduce backwards incompatibility we could:

    • We could return pkg_resources in setuptools.build_meta:__legacy__.get_requires_for_build_sdist/wheel (either by default, or by using an heuristic like searching for the pkg_resources string in setup.py.
  8. cdce8p commented on May 27, 2025

    @cdce8p
    Member

    I tried uploading a copy of pkg_resources to PyPI, but it seems that name is blocked:

    ...

    I don't think it's worth trying to reclaim that name, so I'm going to assume that supplying a separate pkg_resources package to supplement setuptools without pkg_resources. Environments that rely on setuptools will simply have to install setuptools<81.

    Does the project need to be named pkg_resources? Wouldn't something like pkg_resources_backport (or similar) work?

    You're right that replacing the deprecated APIs isn't an issue, at least not for actively maintained projects. What I'm a bit concerned about is unnecessarily breaking those which haven't received an update in a while. Especially in larger projects those dependencies aren't always avoidable.

    For Home Assistant we had a similar situation with the move to Python 3.13. The removal of stdlib modules broke a lot of packages. We wouldn't be able to use 3.13 now if it weren't for backport packages. I'd assume it will be similar for the pkg_resources removal. Yes, pinning setuptools is an option but not a very good one IMO.

  9. jaraco commented on May 27, 2025

    @jaraco
    MemberAuthor

    To be sure, if there's a common/impactful scenario where the presence of a backfill project would help, I'll definitely work on creating that project. The problem is that the scenarios I've thought of where it might help would be just as easily addressed by pinning Setuptools. After all, if you can require or install pkg_resources, that's the point where you could also require setuptools<81, no? The dependency is at runtime and not build time, so the complications that come with being a build time dependency are moot, I think.

    If users are noticing the warning now, let's explore those cases and see what options are available.

  10. cdce8p commented on May 27, 2025

    @cdce8p
    Member

    After all, if you can require or install pkg_resources, that's the point where you could also require setuptools<81, no?

    Yes, though I'd prefer to not have to do that as it "forever" limits which setuptools version is used. There might be other packages in the future which depend on a newer version and would thus be incompatible.

    "forever" might be an exaggeration but some packages might not have received an update in over 3 years. Those are unlikely to get fixed. So the setuptools pin would have to stay until these are eventually removed.

    The dependency is at runtime and not build time, so the complications that come with being a build time dependency are moot, I think.

    If it were a build time dependency, I don't think there is an option to remove it. Thankfully this shouldn't be the case (?). Yes PIP_CONSTRAINTS exists but it's not easy to use for most people and until overwriting build requirements gets easier this would be the only option.

  11. jaraco commented on May 27, 2025

    @jaraco
    MemberAuthor

    Yes, though I'd prefer to not have to do that as it "forever" limits which setuptools version is used. There might be other packages in the future which depend on a newer version and would thus be incompatible.

    Acknowledged. And if there's a scenario that warrants this bridge, we'll deal with it then.

  12. Avasam commented on Jun 1, 2025

    @Avasam
    Contributor

    FWIW, there's already an issue opened concerning distributing pkg_resources separatly: #863

    Although nowadays the answer might be "use importlib_metadata".

  13. mauritsvanrees commented on Jun 4, 2025

    @mauritsvanrees
    SponsorContributor

    I am maintaining zc.buildout. This still heavily depends on pkg_resources. See buildout/buildout#685. As described in that ticket, theoretically it might be possible to get rid of this dependency, but likely this needs breaking changes in the whole ecosystem of Buildout extensions and recipes. This breakage would probably not be worth the trouble.

    So for Buildout it could be useful to have a backport of pkg_resources available.
    Alternatively, I am pondering to just copy the current pkg_resources package to zc.buildout. I just did the same for the removed package_index.py module.

    Note that supporting pkg_resources namespaces could also be a reason for a backport package. But for my part (speaking as Plone release manager), the Zope and Plone communities are working on updating our packages to move to native namespaces. We want them completely gone in Plone 6.2, which is expected in the fall of this year. It could prove more difficult for Plone add-ons, which are often using the collective.* namespace. So a backport could have value there.

    For the record, you can install Zope and Plone just fine with pip, and many are using just that, plus some other tooling. But Buildout has useful constructs that go beyond merely installing packages, so old farts like me still appreciate it. ;-)

  14. jaraco commented on Feb 8, 2026

    @jaraco
    MemberAuthor

    Since setuptools no longer relies on pkg_resources, I'm going to close this issue. We can use #863 to track the publishing of a separate pkg_resources backport package.

  15. CAM-Gerlach commented on Feb 8, 2026

    @CAM-Gerlach

    Hey @jaraco , seems the pkg_resources documentation needs an update as it still lists pkg_resources as only "deprecated", with no mention of it actually being removed (nor active plans for its removal). That was my first port of call to check for its removal when the Lektor-based build system of our legacy site broke (in star-fleet-tours/star-fleet-tours-website#101 ) due to missing pkg_resources, since I recalled you'd deprecated it, but as I didn't see anything there I checked into a few other things before checking the changelog.

    I'd offer to contribute a PR, but I'm traveling at the moment and I figure you know what you want to say as the maintainer and all :)

  16. abravalheri commented on Feb 9, 2026

    @abravalheri
    Contributor

    @CAM-Gerlach, would #5173 solve the problem?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions