ModuleNotFoundError: No Module Named ‘pkg_resources’ — What It Is and How to Fix It
Getting ModuleNotFoundError: no module named ‘pkg_resources’ in Python? This guide explains exactly why it happens and gives you working fixes for all platforms and Python versions.
You install a Python package or run a script and get this in the middle of the output:
ModuleNotFoundError: No module named 'pkg_resources'
The ModuleNotFoundError: no module named 'pkg_resources' error is increasingly common, especially on Python 3.12 and newer versions. It confuses developers because pkg_resources isn’t something most people install explicitly — it’s supposed to be there automatically. This guide explains where it comes from and gives you clear, working fixes.
What Is pkg_resources?
pkg_resources is part of the setuptools package. It provides utilities for working with Python package metadata — things like finding installed packages, loading entry points, and checking version requirements.
Many older Python packages import from it directly:
from pkg_resources import get_distribution
import pkg_resources
For years, setuptools was bundled with Python and available in every environment. That changed with Python 3.12, which removed setuptools from the standard installation. Now you have to install it explicitly, and if you haven’t, anything that depends on pkg_resources will fail with this error.
Why It Appears More on Python 3.12+
Starting with Python 3.12, the Python core team removed several packages that were previously bundled automatically, including setuptools. The rationale: these are third-party packages that belong in the Python Package Index (PyPI), not in the standard library.
The result: any code or tool that assumed setuptools was always available breaks on Python 3.12+ unless setuptools is installed in the environment.
If you recently upgraded to Python 3.12 or 3.13 and started seeing this error, that’s why.
Fix 1: Install or Upgrade setuptools
The most direct fix. Open your terminal and run:
pip install --upgrade setuptools
On macOS or Linux if you have multiple Python versions:
pip3 install --upgrade setuptools
On Windows with the py launcher:
py -m pip install --upgrade setuptools
After installation, verify:
python -c "import pkg_resources; print(pkg_resources.__version__)"
If this prints a version number without error, you’re done. This single command fixes the issue in the vast majority of cases.
Fix 2: Upgrade pip, setuptools, and wheel Together
When your environment is stale or partially broken, upgrading all three packaging tools at once is a cleaner reset:
pip install --upgrade pip setuptools wheel
pip is the installer, setuptools provides pkg_resources, and wheel handles pre-compiled binary packages. Keeping all three current prevents a range of dependency issues that show up together.
Fix 3: Reinstall setuptools
If upgrading doesn’t work because setuptools is partially installed or corrupted, uninstall and reinstall it cleanly:
pip uninstall setuptools
pip install setuptools
Or as a single force-reinstall:
pip install --force-reinstall setuptools
The --force-reinstall flag makes pip reinstall the package even if it believes the current version is already installed.
Fix 4: Fix It Inside a Virtual Environment
If you’re working inside a virtual environment and hitting this error, the cleanest fix is often to recreate the venv:
# Deactivate if active
deactivate
# Delete the broken venv
rm -rf .venv # Linux/macOS
rmdir /s /q .venv # Windows
# Create a fresh venv
python -m venv .venv
# Activate it
source .venv/bin/activate # Linux/macOS
.venv\Scripts\activate # Windows
# Install setuptools and your dependencies
pip install setuptools
pip install -r requirements.txt
Virtual environments created with Python 3.12+ don’t automatically include setuptools. A fresh venv with an explicit pip install setuptools before installing anything else sets you up cleanly.
Fix 5: Linux Package Manager (Debian/Ubuntu)
On Debian/Ubuntu-based systems, if you installed Python through apt, there’s a system-managed way to get setuptools:
sudo apt update
sudo apt install python3-setuptools
This installs the system version of setuptools. If you’re using a virtual environment, you still need pip install setuptools inside the venv — the system-level package won’t be visible inside the venv.
Fix 6: The setuptools 82.0 Issue
In 2025 and 2026, some developers hit this error even after installing setuptools because setuptools version 82.0 made architectural changes that removed pkg_resources from certain import paths.
If you’re still getting the error after pip install setuptools, try pinning to an older version:
pip install "setuptools<82"
This gives you a version that includes pkg_resources in the expected location. Check for updates on the specific package causing the issue — many packages have released fixes that remove their dependency on pkg_resources in favor of the modern importlib.metadata module.
The Long-Term Fix: importlib.metadata
For developers maintaining packages that currently import from pkg_resources, the modern replacement is Python’s built-in importlib.metadata:
# Old way (requires setuptools):
from pkg_resources import get_distribution
version = get_distribution('mypackage').version
# New way (built into Python 3.8+):
from importlib.metadata import version
ver = version('mypackage')
importlib.metadata is part of the Python standard library from 3.8 onward. It does most of what pkg_resources does for package metadata, without any external dependency. If you’re writing a new package or updating an old one, migrating away from pkg_resources is the right long-term move.
Python’s packaging ecosystem continues to evolve, and staying current with these changes is part of maintaining professional Python projects. The same principle of keeping tools and dependencies up to date applies across the broader software development world, as discussed in Blockchain Technology Can Help SMEs Upgrade on DataWider — where technology adoption and modernization are explored in a business context.
Diagnosing Which Fix You Need
Run through this checklist:
- Check your Python version:
python --version. If it’s 3.12+, you need to install setuptools manually. - Check if setuptools is installed:
pip show setuptools. If it’s not listed, install it. - Check if you’re in a venv: Does your terminal prompt show a venv name? If the venv was created without setuptools, install it inside.
- Check setuptools version:
pip show setuptools | grep Version. If it’s 82.0+, try pinning to<82if the specific package causing the issue isn’t yet updated. - Check if the package causing the error has updates: Some packages have released new versions that remove the
pkg_resourcesdependency.pip install --upgrade <packagename>may be enough.
Software testing and diagnostics use exactly this kind of systematic root-cause analysis. Software Testing Tools — Are They Extremely Useful on DataWider discusses how diagnostic thinking and tooling work together.
Key Takeaways
ModuleNotFoundError: no module named 'pkg_resources' means setuptools is not installed in your Python environment.
Here’s the fix priority list:
- Fastest fix:
pip install --upgrade setuptools - Full environment reset:
pip install --upgrade pip setuptools wheel - Corrupted install:
pip install --force-reinstall setuptools - Broken venv: Delete and recreate the virtual environment
- Linux system Python:
sudo apt install python3-setuptools - setuptools 82+ issue: Pin with
pip install "setuptools<82" - Long-term fix: Migrate from
pkg_resourcestoimportlib.metadata
Python 3.12+ no longer bundles setuptools, so this error will become more common. Installing it explicitly is now a normal part of Python environment setup.