# ModuleNotFoundError: No module named 'pkg_resources': how to fix it

> ModuleNotFoundError: No module named 'pkg_resources' means code imported pkg_resources, which is part of setuptools, not the standard library. Python 3.12 stopped pre-installing setuptools in new virtual environments, and setuptools 82.0.0 removed pkg_resources altogether, so installing the latest setuptools no longer brings it back. Upgrade the package that imports it, move your own code to importlib.metadata and importlib.resources, or pin setuptools<82 as a stopgap.

Source: https://livops.dev/en/guides/error-python-no-module-named-pkg-resources

By Livops team, the people who build and run Livops. Updated 2 December 2026.

The install or the app stops with this, usually at the end of a traceback that starts inside a library:

```text
ModuleNotFoundError: No module named 'pkg_resources'
```

The code imported `pkg_resources`, and the Python environment running it does not have one. This page explains where `pkg_resources` came from and why it disappeared, why `pip install setuptools` is no longer enough, how to find which package imports it, and the fix for each case.

## What the error means

`pkg_resources` was never part of Python's standard library. It is part of the **setuptools** package, as Python's 3.12 release notes put it[1]. Two separate changes now make it missing.

### Python 3.12 stopped pre-installing setuptools

Up to Python 3.11, an environment created with `venv` came with setuptools, and so with `pkg_resources`, without anyone asking for it. Python 3.12 removed the bundled setuptools wheel from `ensurepip` and stopped installing setuptools in new virtual environments: `distutils`, `setuptools`, `pkg_resources` and `easy_install` are no longer available by default[1]. The `venv` docs record the same change: from 3.12, setuptools is no longer a core venv dependency[2]. The release notes say projects that rely on these at runtime should declare setuptools as a dependency[1].

### Setuptools 82.0.0 removed pkg_resources

That advice no longer works on its own. Setuptools has discouraged `pkg_resources` for years: since 67.5.0 (March 2023) importing it emits a `DeprecationWarning`[4], and 80.9.0 (May 2025) set a deadline for its removal[4]. **Setuptools 82.0.0, released on 8 February 2026, removed it**[4]. Setuptools' own docs now say `pkg_resources` is no longer included in current installations as of 82.0.0, and that projects must migrate away from it[3].

So `pip install setuptools` today installs a setuptools without `pkg_resources`. The changelog's advice for projects that still rely on it is to depend on an older setuptools[4]. The lasting fix is the replacements setuptools recommends: `importlib.resources` for resource files, `importlib.metadata` for distribution metadata and entry points, and the `packaging` package for parsing versions and requirements[3].

## Causes, most common first

### 1. An old library imports pkg_resources when your app starts

The install passes, and the app stops at startup with the error deep in a library's traceback. Many libraries read their own version with `pkg_resources` at import time.

APScheduler is a well-known case. Version 3.10.1 starts with `from pkg_resources import get_distribution, DistributionNotFound`[12] and lists `setuptools >= 0.7` among its install requirements[13]. That requirement is met by setuptools 82 and later, which have no `pkg_resources`, so even with setuptools installed the import fails. APScheduler 3.10.2 replaced its uses of `pkg_resources` with `importlib.metadata`[11].

**Fix:** upgrade the package to a release that no longer imports `pkg_resources`:

```text
APScheduler>=3.10.2
```

For another package, the traceback names the file; the package is the folder under `site-packages` it lives in. Look in its changelog for the release that dropped `pkg_resources` and raise your pin to it.

### 2. Your own code imports pkg_resources

If the last frame of the traceback is your own file, replace the call. The table under **Replacing pkg_resources in your code** below maps each call; most code needs one line changed.

### 3. An old package's setup.py imports it while pip builds it

The deploy fails during install, and pip's output shows a `setup.py` importing `pkg_resources`. pip builds packages in an isolated environment with their own build dependencies[9], and a project with a `setup.py` but no `[build-system]` table in `pyproject.toml` gets `setuptools>=40.8.0` as its build requirement[9]. Setuptools 82 and later satisfy that, so the build runs without `pkg_resources` and fails, whatever you have installed yourself.

**Fixes**, in this order:

1. **Upgrade the package** to a release that ships a wheel for your Python, so pip installs it without building anything. Why pip builds from source at all: [Failed building wheel](https://livops.dev/en/guides/error-pip-failed-building-wheel).
2. **Constrain setuptools inside the build environment.** pip 25.3 and later accept a build constraints file that applies only to isolated build environments[10]:

```sh
echo "setuptools<82" > build-constraints.txt
pip install --build-constraint build-constraints.txt -r requirements.txt
```

The option can also be set with the `PIP_BUILD_CONSTRAINT` environment variable. Since pip 26.2, an ordinary constraints file, `PIP_CONSTRAINT` included, no longer affects isolated builds; use build constraints for that[10].

### 4. Nothing can change today

When the package that imports `pkg_resources` cannot be upgraded right now, pin setuptools below 82 in `requirements.txt`, following setuptools' own advice to depend on an older version[4]:

```text
setuptools<82
```

The import works again, with a deprecation warning[4]. Treat it as time bought: `pkg_resources` is no longer maintained[3], and the pin holds you on an old setuptools until the dependency moves on.

## Replacing pkg_resources in your code

`importlib.metadata` is in the standard library since Python 3.8[5], and its docs describe it as superseding `pkg_resources` together with `importlib.resources`[5]. `importlib.resources.files()` is there since Python 3.9[6].

| pkg_resources | Replace with |
| --- | --- |
| `get_distribution("x").version` | `importlib.metadata.version("x")`[5] |
| `get_distribution("x")` | `importlib.metadata.distribution("x")`[5][8] |
| `DistributionNotFound` | `importlib.metadata.PackageNotFoundError`[5] |
| `iter_entry_points("group")` | `importlib.metadata.entry_points(group="group")`[5][8] |
| `resource_filename(pkg, name)` | `importlib.resources.as_file(files(pkg) / name)`, used in a `with` block[7] |
| `resource_stream(pkg, name)` | `files(pkg).joinpath(name).open("rb")`[7] |
| `resource_string(pkg, name)` | `files(pkg).joinpath(name).read_bytes()`[7] |
| `resource_listdir("my.package", "sub")` | `files("my.package.sub").iterdir()`[7] |
| `parse_version`, `Requirement` | `packaging.version`, `packaging.requirements` (the `packaging` package)[3] |

APScheduler's version lookup is a typical case. In 3.10.1 it read[12]:

```python
from pkg_resources import get_distribution, DistributionNotFound

try:
    release = get_distribution('APScheduler').version.split('-')[0]
except DistributionNotFound:
    release = '3.5.0'
```

The same lines with the standard library:

```python
from importlib.metadata import version, PackageNotFoundError

try:
    release = version('APScheduler').split('-')[0]
except PackageNotFoundError:
    release = '3.5.0'
```

Some features have no drop-in replacement. `importlib.metadata` does not manage a "working set" or resolve `require()` at runtime[8], and projects that rely on `pkg_resources` for namespace packages are told by setuptools to stay on an older version[4]. Those need a small redesign, not a one-line change.

## How to find which package imports it

Run these with the same Python the app runs with:

```sh
python --version
python -m pip show setuptools
python -c "import pkg_resources"
```

If `pip show` reports no setuptools, or a version of 82 or later, the last line fails with the same error. Then read the traceback from the bottom up: the last frame outside the standard library is the package to upgrade, or your own file to edit. For an install failure, the package being built is named in pip's lines above the traceback.

The same Python 3.12 change also removed `distutils`: if that is the module missing, see [No module named 'distutils'](https://livops.dev/en/guides/error-python-no-module-named-distutils), and for the `imp` module, [No module named 'imp'](https://livops.dev/en/guides/error-python-no-module-named-imp). If the missing module is one your own code needs, the general case is in [ModuleNotFoundError: No module named](https://livops.dev/en/guides/error-module-not-found-python).

## On Livops

- **A runtime failure stops as `start_failed`.** When a library imports `pkg_resources` as the app starts (cause 1), the build passes and the deploy fails as `start_failed`. The reason is on the **Logs** page. A web app's previous version keeps running; a bot's was stopped before the new one started, so the bot is down until a deploy succeeds.
- **A build failure stops as `install_failed`.** When an old package's `setup.py` needs `pkg_resources` (cause 3), the deploy stops as `install_failed`, pip's output is in the build log, often with a **Tip:** line at its end, and the old version keeps running.
- **The fix goes in requirements.txt.** Raise the pin of the package that imports `pkg_resources`, or add `setuptools<82` as a stopgap, in `requirements.txt` and deploy again, rather than installing anything by hand.
- **Choose the Python.** Livops runs Python 3.10 to 3.14 and reads the version from a `.python-version` file at the project root.
- **The assistant explains.** When a build fails, the log shows why and the assistant explains it. Changing the pin is yours to commit.

A Python web app costs **39 credits a month**; a bot, worker or cron job **19**. The install errors are in [Install failed](https://livops.dev/en/docs/error-install), and the startup ones in [The app did not start](https://livops.dev/en/docs/error-start), including [Python could not find a module](https://livops.dev/en/docs/error-start#py-module).

## Questions

**Is pkg_resources part of the Python standard library?**

No. It has always shipped inside the setuptools package, and Python's 3.12 release notes say so. It used to be present because environments came with setuptools pre-installed.

**I ran pip install setuptools and the error is still there. Why?**

Setuptools 82.0.0, released in February 2026, removed pkg_resources. Installing the latest setuptools gives you a release without it. Upgrade the package that imports pkg_resources, or pin setuptools<82 in requirements.txt as a stopgap.

**Why does it work on my machine and fail on the server?**

Your machine most likely has an older setuptools that still contains pkg_resources, often in an environment created with Python 3.11 or earlier, which came with setuptools pre-installed. A fresh environment on the server gets either no setuptools or the newest one. Compare python -m pip show setuptools in both places.

**Is pinning setuptools<82 safe?**

As a stopgap, yes. pkg_resources is no longer maintained, and it has emitted deprecation warnings since setuptools 67.5.0. Use the pin to get a deploy working, then upgrade or migrate the code that imports pkg_resources.

**What replaces pkg_resources.get_distribution(name).version?**

importlib.metadata.version(name), in the standard library since Python 3.8. It raises importlib.metadata.PackageNotFoundError where pkg_resources raised DistributionNotFound.

**What replaces pkg_resources.resource_filename?**

importlib.resources.files(package) joined with the file name, wrapped in importlib.resources.as_file() when you need a real path on disk. files() is in the standard library since Python 3.9.

**Which Python versions does Livops run?**

Python 3.10 to 3.14. Put the version in a .python-version file at the project root, for example 3.12.

## Sources

1. [Python docs — What's New In Python 3.12](https://docs.python.org/3/whatsnew/3.12.html). Checked 2 December 2026.
2. [Python docs — venv, creation of virtual environments](https://docs.python.org/3/library/venv.html). Checked 2 December 2026.
3. [Setuptools docs — Package Discovery and Resource Access using pkg_resources](https://setuptools.pypa.io/en/latest/deprecated/pkg_resources.html). Checked 2 December 2026.
4. [Setuptools docs — History](https://setuptools.pypa.io/en/latest/history.html). Checked 2 December 2026.
5. [Python docs — importlib.metadata](https://docs.python.org/3/library/importlib.metadata.html). Checked 2 December 2026.
6. [Python docs — importlib.resources](https://docs.python.org/3/library/importlib.resources.html). Checked 2 December 2026.
7. [importlib_resources — Migration guide](https://importlib-resources.readthedocs.io/en/latest/migration.html). Checked 2 December 2026.
8. [importlib_metadata — Migration guide](https://importlib-metadata.readthedocs.io/en/latest/migration.html). Checked 2 December 2026.
9. [pip docs — Build System Interface](https://pip.pypa.io/en/stable/reference/build-system/). Checked 2 December 2026.
10. [pip docs — User Guide (Build Constraints)](https://pip.pypa.io/en/stable/user_guide/). Checked 2 December 2026.
11. [APScheduler — Version history (3.x branch)](https://raw.githubusercontent.com/agronholm/apscheduler/3.x/docs/versionhistory.rst). Checked 2 December 2026.
12. [APScheduler 3.10.1 source — apscheduler/__init__.py](https://raw.githubusercontent.com/agronholm/apscheduler/3.10.1/apscheduler/__init__.py). Checked 2 December 2026.
13. [APScheduler 3.10.1 source — setup.py](https://raw.githubusercontent.com/agronholm/apscheduler/3.10.1/setup.py). Checked 2 December 2026.
