Will setuptools remove `pkg_resource` module in the future?

pkg_resource module in setuptools is marked as deprecated now. Will it be removed in the future?

If so, when will it be removed?

It says to migrate from pkg_resource to importlib.metadata and importlib.resource. But I don’t think it is a easy work. There is no drop-in replacement for Requirement and WorkingSet class in pkg_resource, is there any tutorial about it?? or does anyone know how to commit the migration?

Specifiers and Requirements in the PyPA packaging project appear to be the replacement for pkg_resources Requirement functionality.

WorkingSet was always rather rudimentary, and was explicitly recommended for quick n’ dirty hacky scripts rather than serious use. resolvelib is a somewhat lower-level but far more sophisticated and robust replacement, which is what pip itself uses at the low-level for resolving dependencies.

@abravalheri , maybe worth adding a mention of packaging in the deprecation notice too, since a number of other pkg_resources APIs have their replacements there as well (e.g. version parsing and handling, various utilities, etc)?


I think distlib might also have some overlapping features with pkg_resources.

1 Like

I’m not entirely sure how the above adds to the conversation here, as it appears to simply repeat the information in the question and offer very general advice, which is actually not correct—as mentioned, there is a (mostly) drop-in replacement for pkg_resources.Requirement, packaging.Requirement, and I’m not aware of specific migration guides on the packaging.python.org site.

Did you write the above response yourself, or was it generated with an LLM (like ChatGPT)? That would explain the issues here, as the latter can very often write answers that look right to an untrained eye, but can actually be quite incorrect, misleading and unhelpful. We suggest you either avoid doing so, or else use its output as a basis for your own writing after carefully fact-checking it and making sure the response give is actually helpful in the context of the discussion. Thanks.


I’m mostly just curious, what do people use WorkingSet for, except for getting installed package metadata? (which is well replaced with importlib.metadata and packaging)

From my experience migrating pip away from pkg_resource, most parts in WorkingSet are in general pretty broken, not usable for anything practical, and only add unwanted overhead, to be honest. But that may very likely just because most people have different use cases from pip.

I was once forced to use it due to me appending to sys.path and pkg_resources.working_set having a cache that I had to update because something else was using one of pkg_resources APIs that depended on it but I don’t think that counts :slight_smile:

1 Like

Thank you very much for the pointer @CAM-Gerlach. I will try to add this to the docs soon (if any other member of the community wants to beat me to that and submit a PR, please go ahead :smile: )

1 Like

Thank you very much for summarising Tzu-ping. I think that is the main point.

Some APIs in pkg_resources like WorkingSet have a lot of side effects and unwanted performance hits. No one seems to have figured out how to implement those features in a clean and performant way. Therefore, the only parts of pkg_resources that are worth migrating to are effectively the ones covered by importlib-resources, importlib-metadata and packaging.

Anything else may need some rethinking.