# Will setuptools remove \`pkg\_resources\` module in the future?

**URL:** <https://discuss.python.org/t/will-setuptools-remove-pkg-resources-module-in-the-future/27182>\
**Category:** Packaging\
**Created:** [May 28, 2023, 7:31am UTC](https://discuss.python.org/t/will-setuptools-remove-pkg-resources-module-in-the-future/27182 "2023-05-28T07:31:02Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![evan0greenup](https://avatars.discourse-cdn.com/v4/letter/e/d26b3c/32.png) [@evan0greenup](https://discuss.python.org/u/evan0greenup)\
**Post date:** [May 28, 2023, 7:31am UTC](https://discuss.python.org/t/will-setuptools-remove-pkg-resources-module-in-the-future/27182/1 "2023-05-28T07:31:02Z")

</div>

`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?

---

<div class="post-metadata">

**Author:** ![CAM-Gerlach](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/cam-gerlach/32/3688_2.png) [@CAM-Gerlach](https://discuss.python.org/u/CAM-Gerlach)\
**Post date:** [May 28, 2023, 8:46am UTC](https://discuss.python.org/t/will-setuptools-remove-pkg-resources-module-in-the-future/27182/2 "2023-05-28T08:46:46Z")

</div>

> [@evan0greenup](#):
>
> 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](https://packaging.pypa.io/en/stable/specifiers.html) and [Requirements](https://packaging.pypa.io/en/stable/requirements.html) in the [PyPA `packaging` project](https://packaging.pypa.io/en/stable/index.html) 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](https://pypi.org/project/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)?

---

<div class="post-metadata">

**Author:** ![sinoroc](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/sinoroc/32/1607_2.png) [@sinoroc](https://discuss.python.org/u/sinoroc)\
**Post date:** [May 28, 2023, 9:06am UTC](https://discuss.python.org/t/will-setuptools-remove-pkg-resources-module-in-the-future/27182/3 "2023-05-28T09:06:33Z")

</div>

I think [_`distlib`_](https://pypi.org/project/distlib/) might also have some overlapping features with _`pkg_resources`_.

---

<div class="post-metadata">

**Author:** ![CAM-Gerlach](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/cam-gerlach/32/3688_2.png) [@CAM-Gerlach](https://discuss.python.org/u/CAM-Gerlach)\
**Post date:** [May 31, 2023, 5:56pm UTC](https://discuss.python.org/t/will-setuptools-remove-pkg-resources-module-in-the-future/27182/5 "2023-05-31T17:56:46Z")

</div>

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`](https://packaging.pypa.io/en/stable/requirements.html), and I’m not aware of specific migration guides on the [packaging.python.org](http://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.

---

<div class="post-metadata">

**Author:** ![uranusjr](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/uranusjr/32/103_2.png) [@uranusjr](https://discuss.python.org/u/uranusjr)\
**Post date:** [June 1, 2023, 8:23am UTC](https://discuss.python.org/t/will-setuptools-remove-pkg-resources-module-in-the-future/27182/6 "2023-06-01T08:23:41Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![jack1142](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/jack1142/32/2224_2.png) [@jack1142](https://discuss.python.org/u/jack1142)\
**Post date:** [June 1, 2023, 11:11am UTC](https://discuss.python.org/t/will-setuptools-remove-pkg-resources-module-in-the-future/27182/7 "2023-06-01T11:11:17Z")

</div>

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 🙂

---

<div class="post-metadata">

**Author:** ![abravalheri](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/abravalheri/32/4990_2.png) [@abravalheri](https://discuss.python.org/u/abravalheri)\
**Post date:** [June 6, 2023, 2:36pm UTC](https://discuss.python.org/t/will-setuptools-remove-pkg-resources-module-in-the-future/27182/8 "2023-06-06T14:36:36Z")

</div>

> [@CAM-Gerlach](#):
>
> @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)?

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 😄 )

---

<div class="post-metadata">

**Author:** ![abravalheri](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/abravalheri/32/4990_2.png) [@abravalheri](https://discuss.python.org/u/abravalheri)\
**Post date:** [June 6, 2023, 2:43pm UTC](https://discuss.python.org/t/will-setuptools-remove-pkg-resources-module-in-the-future/27182/9 "2023-06-06T14:43:00Z")

</div>

> [@uranusjr](#):
>
> 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.

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.

---

<div class="post-metadata">

**Author:** ![ChrisBarker-NOAA](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/chrisbarker-noaa/32/17339_2.png) [@ChrisBarker-NOAA](https://discuss.python.org/u/ChrisBarker-NOAA)\
**Post date:** [April 9, 2024, 12:24am UTC](https://discuss.python.org/t/will-setuptools-remove-pkg-resources-module-in-the-future/27182/10 "2024-04-09T00:24:01Z")

</div>

Finding this a year later, but a note:

I am updating a project (that I did not originally write) to remove `pkg_resources`, and finding it very trick, as I’m not that familiar with `pkg_resources`, nor this package.

What would help a LOT is a porting guide.

There’s docs saying that you can find _most_ of it in `importlib`, or `packaging`, or others? – but no one-to-one mapping that I could find.

Topic at hand, and why I found this thread:

I’m trying to replace `pkg_resources.working_set.iter_entry_points` – and no idea how to do that.

Plugging away!

Anyway, if there is a migration guide, can someone point me to it? otherwise _maybe_ we could start writing one? Or simply add it to the `pkg_resources` docs – for each function, a note to how to not use it 🙂

---

<div class="post-metadata">

**Author:** ![mdrissi](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/mdrissi/32/5427_2.png) [@mdrissi](https://discuss.python.org/u/mdrissi)\
**Post date:** [April 9, 2024, 12:40am UTC](https://discuss.python.org/t/will-setuptools-remove-pkg-resources-module-in-the-future/27182/11 "2024-04-09T00:40:36Z")

</div>

> [@ChrisBarker-NOAA](#):
>
> iter\_entry\_points

[Migration guide - importlib\_resources 6.4.1.dev1+g6fa0a7a.d20240321 documentation](https://importlib-resources.readthedocs.io/en/latest/migration.html#migration-guide) is the migration guide. Not every method in pkg\_resources has an equivalent and yours (entrypoints related stuff) is actually one mentioned as not having one and you’ll need an entirely new way.

---

<div class="post-metadata">

**Author:** ![ChrisBarker-NOAA](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/chrisbarker-noaa/32/17339_2.png) [@ChrisBarker-NOAA](https://discuss.python.org/u/ChrisBarker-NOAA)\
**Post date:** [April 9, 2024, 6:33pm UTC](https://discuss.python.org/t/will-setuptools-remove-pkg-resources-module-in-the-future/27182/12 "2024-04-09T18:33:39Z")

</div>

Thanks! Sure wish I’d found that when I started this 🙂

> [@mdrissi](#):
>
> Not every method in pkg\_resources has an equivalent and yours (entrypoints related stuff) is actually one mentioned as not having one and you’ll need an entirely new way.

Actually, I did find a solution, and it wasn’t _that_ different:

For the purposed of this archive – the pkg\_resources code was:

```python
from pkg_resources import working_set

checkers = working_set.iter_entry_points("compliance_checker.suites")

```

and the replacement is:

```python
import importlib
checkers = importlib.metadata.entry_points(group='compliance_checker.suites')

```

The differences are that `working_set.iter_entry_points` returns an iterable (duh), and `importlib.metadata.entry_points` is a realized list (which is iterable, so no problem there.

The other difference is that importlib EntryPoint objects have a `.load()` method, instead of the setuptools EntryPoint objects, which have a `.resolve()` method.

So at least for that use-case, it was a pretty easy replacement.

Also – I notice that the migration guide is part of the backport of importlib – which is why I didn’t find it. Maybe it could be in the main Python docs? or a link to it? or in the setuptools docs?

So now I don’t know where to post a PR ☹

---

<div class="post-metadata">

**Author:** ![ferdnyc](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/ferdnyc/32/6325_2.png) [@ferdnyc](https://discuss.python.org/u/ferdnyc)\
**Post date:** [April 15, 2024, 8:40pm UTC](https://discuss.python.org/t/will-setuptools-remove-pkg-resources-module-in-the-future/27182/13 "2024-04-15T20:40:43Z")

</div>

> [@ChrisBarker-NOAA](#):
>
> Also – I notice that the migration guide is part of the backport of importlib – which is why I didn’t find it. Maybe it could be in the main Python docs? or a link to it? or in the setuptools docs?
> 
> So now I don’t know where to post a PR ☹

Unlike `pkg_resources`, `importlib` is part of the Python Standard Library. [The `importlib.resources` documentation](https://docs.python.org/3/library/importlib.resources.html) in the Python Standard Library documentation does actually link to the migration guide:

> NOTE: This module provides functionality similar to [pkg\_resources](https://setuptools.readthedocs.io/en/latest/pkg_resources.html) [Basic Resource Access](https://setuptools.readthedocs.io/en/latest/pkg_resources.html#basic-resource-access) without the performance overhead of that package. This makes reading resources included in packages easier, with more stable and consistent semantics.
> 
> The standalone backport of this module provides more information on [using importlib.resources](https://importlib-resources.readthedocs.io/en/latest/using.html) and [migrating from pkg\_resources to importlib.resources](https://importlib-resources.readthedocs.io/en/latest/migration.html).

The `pkg_resources` deprecation notice, in turn, links to the `importlib.resources` documentation, even in `pydoc3` form:

```console
$ pydoc3 pkg_resources
Help on package pkg_resources:

NAME
    pkg_resources

DESCRIPTION
    Package resource API
    --------------------

[...8<...snip...8<...]

    This module is deprecated. Users are directed to
    `importlib.resources <https://docs.python.org/3/library/importlib.resources.html>`_
    and
    `importlib.metadata <https://docs.python.org/3/library/importlib.metadata.html>`_
    instead.

```

I suppose it could link _directly_ to the migration guide as well, but since it’s going away it seems more important that the `importlib.resources` documentation reference the guide, which it already does.

---

<div class="post-metadata">

**Author:** ![ChrisBarker-NOAA](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/chrisbarker-noaa/32/17339_2.png) [@ChrisBarker-NOAA](https://discuss.python.org/u/ChrisBarker-NOAA)\
**Post date:** [April 15, 2024, 8:54pm UTC](https://discuss.python.org/t/will-setuptools-remove-pkg-resources-module-in-the-future/27182/14 "2024-04-15T20:54:33Z")

</div>

> [@ferdnyc](#):
>
> Standard Library documentation does actually link to the migration guide:

So it does – so chock it up to me being an idiot – not sure how I missed that.

```python
I suppose it could link directly to the migration guide as well

```

that would be good for brain-dead folks like me, but it’s really not in bad shape now – thanks!

---

<div class="post-metadata">

**Author:** ![ferdnyc](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/ferdnyc/32/6325_2.png) [@ferdnyc](https://discuss.python.org/u/ferdnyc)\
**Post date:** [April 15, 2024, 10:50pm UTC](https://discuss.python.org/t/will-setuptools-remove-pkg-resources-module-in-the-future/27182/15 "2024-04-15T22:50:07Z")

</div>

> [@ChrisBarker-NOAA](#):
>
> For the purposed of this archive – the pkg\_resources code was:
> 
> ```python
> from pkg_resources import working_set
> 
> checkers = working_set.iter_entry_points("compliance_checker.suites")
> 
> ```
> 
> and the replacement is:
> 
> ```python
> import importlib
> checkers = importlib.metadata.entry_points(group='compliance_checker.suites')
> 
> ```
> 
> The differences are that `working_set.iter_entry_points` returns an iterable (duh), and `importlib.metadata.entry_points` is a realized list (which is iterable, so no problem there.

Mmm, and the [`hotdoc` code I’m currently staring at](https://github.com/hotdoc/hotdoc/blob/13095ee241b4f2d7b45f73b2752b00568c301d93/hotdoc/utils/utils.py#L151-L162) contains:

```python
def __get_extra_extension_classes(path):
    wset = pkg_resources.WorkingSet([])
    distributions, _ = wset.find_plugins(pkg_resources.Environment(paths))

    for dist in distributions:
        sys.path.append(dist.location)
        wset.add(dist)

    for entry_point in wset.iter_entry_points(group='hotdoc.extensions',
                                              name='get_extension_classes'):
        try:
            activation_function = entry_point.load()
            classes = activation_function()

```

So it does seem like code referring to `WorkingSet` objects (constructed or predefined) and the `EntryPoint`s they access is maybe more common than the [`pkg_resources` documentation optimistically assumes](https://setuptools.pypa.io/en/latest/pkg_resources.html#workingset-objects):

> Note that you will not normally construct `WorkingSet` instances yourself, but instead you will implicitly or explicitly use the global `working_set` instance. For the most part, the `pkg_resources` API is designed so that the `working_set` is used by default, such that you don’t have to explicitly refer to it most of the time.

…and could perhaps use some explicit coverage in the migration guide. Or a link to the [separate `importlib.metadata` migration guide](https://importlib-metadata.readthedocs.io/en/latest/migration.html) — **really** not sure what’s gained by having those as completely separate documents — because it does seem like the two guides could at least _acknowledge_ each other.

The `importlib.metadata` migration guide at least _mentions_ `importlib.resources` (though not its migration guide). Unlike the `importlib.resources` migration guide, which contains no mention of `importlib.metadata` whatsoever, instead dismissively saying:

> projects that use other features (e.g. entry points) will have to find other solutions.

At least for entry points, specifically, that “other solution” is not a mystery — it’s `importlib.metadata`!

---

<div class="post-metadata">

**Author:** ![wolfieboy09](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/wolfieboy09/32/19893_2.png) [@wolfieboy09](https://discuss.python.org/u/wolfieboy09)\
**Post date:** [May 15, 2024, 12:45pm UTC](https://discuss.python.org/t/will-setuptools-remove-pkg-resources-module-in-the-future/27182/16 "2024-05-15T12:45:22Z")

</div>

```py
import importlib.metadata

installed_packages = [package.name for package in importlib.metadata.distributions()]

print(installed_packages)

```

That gets installed packages

---

<div class="post-metadata">

**Author:** ![ferdnyc](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/ferdnyc/32/6325_2.png) [@ferdnyc](https://discuss.python.org/u/ferdnyc)\
**Post date:** [May 18, 2024, 10:01am UTC](https://discuss.python.org/t/will-setuptools-remove-pkg-resources-module-in-the-future/27182/17 "2024-05-18T10:01:10Z")

</div>

\*nod\* It took me two stabs at it, but I did eventually get `hotdoc` [migrated from `pkg_resources` to `importlib.metadata`](https://github.com/hotdoc/hotdoc/pull/280), with its extension support intact.

The code I posted above became something like this, in the New Normal:

```python
from backports.entry_points_selectable import entry_points
try:
    import importlib.metadata as meta
except ImportError:
    import importlib_metadata as meta

def __get_extra_extension_classes(paths):
    path_dists = {
        path: meta.distributions(path=[path])
        for path in paths
    }

    for path, dists in path_dists.items():
        entry_points = [
            dist.entry_points.select(
                group='hotdoc.extensions',
                name='get_extension_classes')
            for dist in dists
        ]
        if entry_points:
            sys.path.append(path)

        for entry_point in itertools.chain(*entry_points):
            classes = __load_entry_point(entry_point, False)

```

Where `__load_entry_point()` does the same `entry_point.load()` and returns the results of executing the `activation_function()`. (It has more error handling than before, so I broke it out.)

---

<div class="post-metadata">

**Author:** ![dimpase](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/dimpase/32/8866_2.png) [@dimpase](https://discuss.python.org/u/dimpase)\
**Post date:** [August 4, 2024, 12:10pm UTC](https://discuss.python.org/t/will-setuptools-remove-pkg-resources-module-in-the-future/27182/18 "2024-08-04T12:10:37Z")

</div>

it’s unfortunate that without `pkg_resource` functionality there seems to be no straightforward way to do something like

```python
pkg_resources.require('wheel>=0.42')

```

Yes, one can certainly `import wheel`, and then manually analyze the value of `wheel. __version__ ` - but this is extra bloat, it really should be standard, no?

---

<div class="post-metadata">

**Author:** ![pradyunsg](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/pradyunsg/32/206_2.png) [@pradyunsg](https://discuss.python.org/u/pradyunsg)\
**Post date:** [August 4, 2024, 8:54pm UTC](https://discuss.python.org/t/will-setuptools-remove-pkg-resources-module-in-the-future/27182/19 "2024-08-04T20:54:00Z")

</div>

FWIW, I’ve edited the title here to refer to the correct import name (which is the only name that this code has).

---

<div class="post-metadata">

**Author:** ![ChrisBarker-NOAA](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/chrisbarker-noaa/32/17339_2.png) [@ChrisBarker-NOAA](https://discuss.python.org/u/ChrisBarker-NOAA)\
**Post date:** [August 20, 2024, 9:16pm UTC](https://discuss.python.org/t/will-setuptools-remove-pkg-resources-module-in-the-future/27182/21 "2024-08-20T21:16:22Z")

</div>

Hmm – I think the idea here is that requirements should be checked at install-time, rather than run-time, which is why this functionality has not been reproduced.

[https://importlib-metadata.readthedocs.io/en/latest/migration.html#pkg-resources-require](https://importlib-metadata.readthedocs.io/en/latest/migration.html#pkg-resources-require)

And the “right” way (or, at least, the closest to `pkg_resources` way) to check the version of an installed package is:

```python
>>> import importlib.metadata
>>> importlib.metadata.version('wheel')
'0.41.2'

```

If you do think that a runtime check is a common and useful thing, then maybe propose an addition to importlib.metadata, e.g.:

```python
importlib.metadata.require_version(dist_name, version_spec)

```

(or check\_version?)

However, it’s unlikely to be accepted – or it would already be there 🙂

I haven’t looked, but I imagine there’s a PyPi package that does this for you.

---

<div class="post-metadata">

**Author:** ![adamjstewart](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/adamjstewart/32/5608_2.png) [@adamjstewart](https://discuss.python.org/u/adamjstewart)\
**Post date:** [February 8, 2026, 4:32pm UTC](https://discuss.python.org/t/will-setuptools-remove-pkg-resources-module-in-the-future/27182/22 "2026-02-08T16:32:56Z")

</div>

For posterity, the answer is yes: [History - setuptools 82.0.0 documentation](https://setuptools.pypa.io/en/stable/history.html#v82-0-0)
