How to fix ModuleNotFoundError: No module named 'pkg_resources' in Python
"No module named 'pkg_resources'" means setuptools (which provides pkg_resources) is missing from your environment. Fix it with pip install --upgrade setuptools.
Quick fix
Fixes ModuleNotFoundError: No module named 'pkg_resources'
which python3
python3 --version
python3 -c "import sys; print(sys.executable)"- Confirm which environment is active
- Install or upgrade setuptools
- If you use a virtual environment, include setuptools when creating it
- Pin setuptools for code that still needs pkg_resources
which python3python3 --versionpython3 -c "import sys; print(sys.executable)"ModuleNotFoundError: No module named 'pkg_resources'
What this error means
`pkg_resources` is not a standalone package you install on its own. It is a module that ships as part of **setuptools**. So `ModuleNotFoundError: No module named 'pkg_resources'` almost always means setuptools is missing from the Python environment that is running your code, or that it was removed/never installed. This has become much more common recently for two reasons: 1. Modern virtual environments no longer bundle setuptools. Since pip 22.1 / Python 3.12, `python -m venv` does not automatically install setuptools (only pip), so any code or dependency that does `import pkg_resources` fails until setuptools is added. 2. setuptools is in the process of removing `pkg_resources`. Starting with setuptools 81 (2025), importing `pkg_resources` emits a deprecation warning, and it is slated for full removal in a future release. On environments pinned to a very new setuptools, code that still relies on `pkg_resources` may break. In short: the component complaining is setuptools' runtime API. The fix is to install or restore setuptools (or, longer term, migrate code off the deprecated `pkg_resources` API).
Typical symptoms
- ModuleNotFoundError: No module named 'pkg_resources' when running a script, tool, or importing a library
- A previously working command (e.g. a CLI entry point) suddenly fails after upgrading Python or recreating a virtualenv
- Error appears inside a fresh virtual environment created with python -m venv
- Third-party packages fail to import or run because they internally do import pkg_resources
- DeprecationWarning: pkg_resources is deprecated as an API (on setuptools 81+)
Common causes
- setuptools is not installed in the active environment (pkg_resources ships with setuptools, not as its own package)
- A virtual environment was created with a modern python -m venv, which no longer installs setuptools by default (pip 22.1+ / Python 3.12+)
- setuptools was uninstalled or upgraded/downgraded in a way that removed or broke pkg_resources
- The wrong Python interpreter or environment is active, so the setuptools you expect isn't on the path
- A package or tool depends on the deprecated pkg_resources API, which newer setuptools (81+) has begun removing
How to fix "ModuleNotFoundError: No module named 'pkg_resources'"
pkg_resources lives in the environment that is actually running your code, so first confirm which Python that is:
which python3
python3 --version
python3 -c "import sys; print(sys.executable)"If you use a virtual environment, make sure it is activated (you should see its name in your prompt):
source myenv/bin/activate # Linux/macOS
myenv\Scripts\activate # WindowsBecause pkg_resources is provided by setuptools, installing/upgrading setuptools fixes the error in the vast majority of cases:
python3 -m pip install --upgrade setuptoolsUsing python3 -m pip (instead of a bare pip) guarantees the install goes into the same interpreter that raised the error. Then verify it imports:
python3 -c "import pkg_resources; print(pkg_resources.__file__)"If that prints a path with no error, the problem is resolved.
Virtual environments created with a recent python -m venv no longer install setuptools automatically. After creating and activating the venv, add setuptools (and refresh pip):
python3 -m venv myenv
source myenv/bin/activate # Windows: myenv\Scripts\activate
python -m pip install --upgrade pip setuptoolsThen reinstall your project dependencies inside the venv:
pip install -r requirements.txtsetuptools 81+ has begun deprecating and removing pkg_resources. If you control the project but cannot immediately migrate, declare setuptools as an explicit dependency and pin it to a version that still ships pkg_resources:
# requirements.txt
setuptools<81or in pyproject.toml:
[project]
dependencies = [
"setuptools<81",
]Treat this as a temporary bridge, not a permanent fix — see Advanced notes for migrating off pkg_resources.
If setuptools is present but the importing package is still broken, reinstall the offending package so its metadata is regenerated:
python3 -m pip install --force-reinstall <package-name>If the environment is in an inconsistent state (e.g. partial upgrades), the cleanest fix is to recreate it from scratch:
deactivate 2>/dev/null
rm -rf myenv # remove only the venv directory, not your project
python3 -m venv myenv
source myenv/bin/activate
python -m pip install --upgrade pip setuptools
pip install -r requirements.txtNote: rm -rf myenv deletes the virtual environment directory only — double-check the path so you don't remove project files. Recreating a venv is safe because it contains no source code, only installed dependencies.
Advanced notes
Long-term, code should stop importing pkg_resources, since setuptools is removing it. Common replacements from the standard library:
- Reading installed package metadata/versions: use importlib.metadata (Python 3.8+). Replace pkg_resources.get_distribution("name").version with importlib.metadata.version("name").
- Accessing data files bundled in a package: use importlib.resources (Python 3.9+ for the modern files() API) instead of pkg_resources.resource_filename / resource_string.
- Parsing/comparing versions: use the packaging library (packaging.version.Version) instead of pkg_resources.parse_version.
System-managed Python (Debian/Ubuntu, Homebrew) may show this error because setuptools is provided by a separate OS package (e.g. python3-setuptools via apt) rather than pip. On those systems, prefer a virtual environment over pip install into the system interpreter to avoid the "externally-managed-environment" (PEP 668) restriction. Avoid pip install --break-system-packages unless you fully understand the consequences — it can corrupt the OS-managed Python; a venv is the safe alternative.
Frequently asked questions
- What does "ModuleNotFoundError: No module named 'pkg_resources'" mean?
- pkg_resources is not a standalone package you install on its own. It is a module that ships as part of setuptools. So ModuleNotFoundError: No module named 'pkg_resources' almost always means setuptools is missing from the Python environment that is running your code, or that it was removed/never installed.
- How do I fix "ModuleNotFoundError: No module named 'pkg_resources'"?
- "No module named 'pkg_resources'" means setuptools (which provides pkg_resources) is missing from your environment. Fix it with pip install --upgrade setuptools.
- What causes "ModuleNotFoundError: No module named 'pkg_resources'"?
- setuptools is not installed in the active environment (pkg_resources ships with setuptools, not as its own package) A virtual environment was created with a modern python -m venv, which no longer installs setuptools by default (pip 22.1+ / Python 3.12+) setuptools was uninstalled or upgraded/downgraded in a way that removed or broke pkg_resources
- Is the "ModuleNotFoundError: No module named 'pkg_resources'" error serious?
- It is a medium-severity error — more of a blocker than a risk. The steps above resolve it.
Official resources & further reading
- 📚Python Official Documentation
- 💬SO: No module named pkg_resources(Stack Overflow)
- 📝
- 📝