In this tutorial, we will show how to solve the Modulenotfounderror: no module named ‘pkg_resources’ error.
Also, we will explain what are the root causes of this error.
Prior to that pkg_resources is a module that is part of the setuptools library.
Wherein setuptools is a collection of enhancements to the Python distutils module that allows developers to more easily build and distribute Python packages.
Additionally, pkg_resources provides runtime support for working with installed Python packages.
What is modulenotfounderror: no module named ‘pkg_resources’?
Modulenotfounderror: no module named ‘pkg_resources’ error occurs when setuptools is not installed in your python environment.
Since the “pkg_resources” module is part of the setuptools library, which is used for packaging and distributing Python projects.
That provides functionality for managing Python package dependencies and metadata.
Therefore the error typically occurs when a Python script or application tries to import a module called “pkg_resources” but the module is not found in the Python environment.
How to solve modulenotfounderror: no module named pkg_resources
So here are the following ways you can consider to fix this error.
- Install or upgrade setuptools
To install or upgrade setuptools, open your terminal and try the following command.
pip install –upgrade setuptools

If you are using Python 3: pip3 install –upgrade setuptools
When you don’t have pip in PATH:
python -m pip install –upgrade setuptools or
python3 -m pip install –upgrade setuptoolsIf you are using Windows: py -m pip install –upgrade setuptools
Note: If the error continues uninstall and install again the module.
- Update pip version, setuptools, and wheel
If the error continues then update the version of your pip, setuptools, and wheel.
To do this follow the commands below:
pip install –upgrade pip setuptools wheel

If you are using Python 3 use this command:pip3 install –upgrade pip setuptools wheel
python -m pip install –upgrade pip setuptools wheel
python3 -m pip install –upgrade pip setuptools wheelIf you are using Windows
py -m pip install –upgrade pip setuptools wheel - Create a virtual environment
After all of the steps you have done above alternatively we can create virtual environment wherein we can install pip and setuptools automatically.
Here are the following commands:
1. Make sure to use the correct version of Python in creating venv
—python -m venv venv2. This is to activate in Unix or MacOS
—source venv/bin/activate3. This is to activate in Windows cmd
—venv\Scripts\activate.bat4. This to activate in Windows Powershell
—venv\Scripts\Activate.ps15. If you don’t have one install the modules in your requirements.txt file
—pip install -r requirements.txt
Root Causes of modulenotfounderror: no module named pkg_resources
The several causes of why this modulenotfounderror: no module named pkg_resources error occurs are the following:
- Missing or outdated setuptools
- If you don’t have setuptools installed, or if it’s outdated, you might encounter the “No module named ‘pkg_resources’” error.
- Additionally, setuptools is a package that provides tools for building, distributing, and installing Python packages.
- Broken “pkg_resources” Module
- If the “pkg resources” module’s files are not properly integrated into the Python environment.
- As a result, the resource files are not accessible to the installed Python environment during the installation of any package.
- Conflicting package installations
- Sometimes, you might have multiple installations of a package on your system, and Python might be trying to import the wrong one.
- This can happen if you’ve installed a package using both pip and your system’s package manager, or if you have multiple versions of Python installed.
Conclusion
In conclusion, Modulenotfounderror: no module named ‘pkg_resources’ error in Python can be caused by a variety of factors, including missing or outdated setuptools, broken “pkg_resources” module, and conflicting package installations.
To fix this error, you can try installing or upgrading setuptools, recreating egg-info, or uninstalling and reinstalling conflicting packages.
We hope that this article has provided you with the information you need to fix this error and continue working with Python packages.
If you are finding solutions to some errors you’re encountering we also have Modulenotfounderror: no module named nlk.
Featured guides worth reading next
Diagnostic checklist for “No module named ‘pkg_resources'”
- Verify pip install target. Run
pip show pkg_resources— if not installed, runpip install pkg_resources. - Check the active Python interpreter.
which python(mac/Linux) orwhere python(Windows). Both pip and python must point to the same environment. - Check virtual environment activation. If you use venv/conda, activate before installing:
source .venv/bin/activate. - Rule out uppercase/lowercase. Python imports are case-sensitive:
import PyPDF2notimport pypdf2. - Rule out the pip-vs-package-name mismatch. Some packages install under a different name than you import (e.g.
pip install beautifulsoup4→import bs4).
Installing pkg_resources
# Standard pip install pip install pkg_resources # In a virtual environment (recommended) python -m venv .venv source .venv/bin/activate # or .venv\Scripts\activate on Windows pip install pkg_resources # With uv (faster alternative) uv pip install pkg_resources
Common causes for “No module named ‘pkg_resources'”
- Python interpreter mismatch. Multiple Python installations can confuse pip. Verify with
which pythonandwhich pip. - Virtual environment not activated. If the venv isn’t activated, pip installs to your system Python instead.
- Notebook kernel mismatch. Jupyter uses a kernel that may differ from your terminal Python. Use
%pip install pkg_resourcesinside the notebook. - Import name differs from install name. pip install beautifulsoup4 → import bs4. Check the package’s PyPI page.
- Windows PATH issues. Ensure Python is on PATH; use
python -m pip installto invoke pip via the correct Python.
Working code example
# Verify install worked import pkg_resources print(getattr(pkg_resources, '__version__', 'no version attribute'))
Best practices
- Always use a virtual environment. Avoids most module-not-found errors.
- Use pip freeze to lock versions.
pip freeze > requirements.txtmakes your setup reproducible. - Consider uv or Poetry. Modern package managers with better dep resolution and reproducibility.
Official documentation
Frequently Asked Questions
What is Python ModuleNotFoundError and what causes it?
ModuleNotFoundError (a subclass of ImportError) is raised when Python cannot find the module you tried to import. Common causes: the package isn’t installed (pip install missing), wrong virtual environment activated, typo in module name, or Python can’t find your local module on the import path. The error message names exactly which module is missing.
How do I fix ‘ModuleNotFoundError: No module named X’?
Run pip install X first. If that succeeds but you still get the error, check which Python you’re using (which python OR python –version) vs which pip (which pip OR pip –version), they must match. Common gotcha: pip points to system Python 3.9 but you’re running python3.11 in a venv. Inside the venv, use python -m pip install X to be sure pip matches the active Python.
Why does my code work in one environment but not another?
Different Python versions or different installed packages. To diagnose: pip freeze > requirements.txt on the working environment, then pip install -r requirements.txt on the broken one. Use virtualenv (python -m venv venv) or conda for every project to avoid system-wide package collisions.
Is ModuleNotFoundError the same as ImportError?
ModuleNotFoundError is a subclass of ImportError added in Python 3.6. It specifically means ‘no such module exists.’ Plain ImportError covers a wider set: module exists but a name inside it can’t be imported (e.g. ‘cannot import name X from Y’). except ImportError catches both; except ModuleNotFoundError catches only the missing-module case.
Where can I find more ModuleNotFoundError fixes?
Browse the ModuleNotFoundError reference hub for 198+ specific module fixes (TensorFlow, Flask, Django, pandas, numpy, etc.). For related issues see ImportError. For broader Python setup see Python Tutorial hub.


