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.
By Livops team, the people who build and run LivopsUpdated
The install or the app stops with this, usually at the end of a traceback that starts inside a library:
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:
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:
- 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.
- Constrain setuptools inside the build environment. pip 25.3 and later accept a build constraints file that applies only to isolated build environments[10]:
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]:
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]:
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:
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:
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’, and for the imp module, No module named ‘imp’. If the missing module is one your own code needs, the general case is in ModuleNotFoundError: No module named.
On Livops
- A runtime failure stops as
start_failed. When a library importspkg_resourcesas the app starts (cause 1), the build passes and the deploy fails asstart_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’ssetup.pyneedspkg_resources(cause 3), the deploy stops asinstall_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 addsetuptools<82as a stopgap, inrequirements.txtand 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-versionfile 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, and the startup ones in The app did not start, including Python could not find a 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
- Python docs — What's New In Python 3.12 (docs.python.org). Checked .
- Python docs — venv, creation of virtual environments (docs.python.org). Checked .
- Setuptools docs — Package Discovery and Resource Access using pkg_resources (setuptools.pypa.io). Checked .
- Setuptools docs — History (setuptools.pypa.io). Checked .
- Python docs — importlib.metadata (docs.python.org). Checked .
- Python docs — importlib.resources (docs.python.org). Checked .
- importlib_resources — Migration guide (importlib-resources.readthedocs.io). Checked .
- importlib_metadata — Migration guide (importlib-metadata.readthedocs.io). Checked .
- pip docs — Build System Interface (pip.pypa.io). Checked .
- pip docs — User Guide (Build Constraints) (pip.pypa.io). Checked .
- APScheduler — Version history (3.x branch) (raw.githubusercontent.com). Checked .
- APScheduler 3.10.1 source — apscheduler/__init__.py (raw.githubusercontent.com). Checked .
- APScheduler 3.10.1 source — setup.py (raw.githubusercontent.com). Checked .
Put your project online today
Connect GitHub or drop a folder. No card is asked for.
Deploy your Python appRelated
- ModuleNotFoundError: No module named 'imp' on Python 3.12+: how to fix itModuleNotFoundError: No module named 'imp' means code running on Python 3.12 or later imported imp, which was deprecated since Python 3.4 and removed from the standard library in 3.12. It is almost always an old release of a library, or old code of your own. Upgrade that library, replace the imp calls with their importlib equivalents, or pin Python 3.11 with a .python-version file while you upgrade.
- ModuleNotFoundError: No module named 'distutils' on Python 3.12+: how to fix itModuleNotFoundError: No module named 'distutils' means code running on Python 3.12 or later imported distutils, which PEP 632 removed from the standard library in 3.12. It is usually an old package pinned in requirements.txt, built from source or imported at runtime. Upgrade that package to a release that supports your Python, install setuptools for code that still imports distutils, or pin Python 3.11 with a .python-version file while you upgrade.
- ModuleNotFoundError: No module named — after a deployPython searched sys.path and could not find the module you import. After a deploy that almost always means the package is not in requirements.txt, is listed under a different name than the one you import, or the start command runs a Python that the packages were not installed into.
- pip: Failed building wheel / failed-wheel-build-for-install — how to fix itpip found no ready-made wheel for a package on your Python version and platform, tried to compile one from source, and the compiler step failed. The fix is almost never to install a compiler: move to a version of the package that ships a wheel for your Python, switch to its binary variant (psycopg[binary], psycopg2-binary), or pin the Python version the package supports.
- python-telegram-bot hosting: deploying a v22 botA python-telegram-bot bot runs as one Application: run_polling() for polling, run_webhook() with the webhooks extra for a webhook. Both stop cleanly on SIGTERM. On Livops it runs from a push with bot.py and requirements.txt for 19 credits a month (19,000 so'm).
- How to run a Python script 24/7 (and keep it running)A script started in a terminal stops when the terminal closes, the SSH connection drops or the laptop sleeps. To keep it running you need something that starts it again: a systemd service with Restart=always, Docker with a restart policy, or a platform's background worker. On Livops it runs as a worker for 19 credits a month (19,000 so'm).
- pip: Getting requirements to build wheel did not run successfully — how to fix itpip found no wheel for the package, so it started building one from source, and the package's own build script failed at the first step, while pip was asking it which build tools it needs. The real error is in the lines inside pip's box: usually a module setup.py imports but never declared (numpy, Cython, pkg_resources), a release too old for your Python, or a missing program such as pg_config. Move to a release with a wheel for your Python, or pin the Python it supports.