Python Can’t Find pkg_resources?

If your project throws “ModuleNotFoundError: No module named ‘pkg_resources'”, your Python environment or package installation may be incomplete. Resolve it early to keep development moving smoothly.

  • Package dependency checks
  • Virtual environment setup
  • pip & setuptools fixes
  • Python environment validation
Talk to a Tech Consultant

Python developers often encounter the ModuleNotFoundError: No module named ‘pkg_resources’ error while installing packages, running scripts, working with virtual environments, or executing applications that depend on third-party libraries. This error typically indicates that the pkg_resources module, which is provided by the setuptools package, is either missing, outdated, corrupted, or inaccessible in the current Python environment.

Although the error message appears simple, it can stem from multiple issues, such as an incomplete Python installation, an improperly configured virtual environment, incompatible package versions, or problems with the Python interpreter being used.

In this guide, you’ll learn what the “No module named ‘pkg_resources'” error means, why it occurs, how to fix it step by step on Windows, macOS, and Linux, and the best practices to prevent it in future Python projects.

What is pkg_resources?

pkg_resources is a module provided by the setuptools package. It allows Python applications to discover installed packages, check package versions, load package resources, and manage dependencies at runtime.

Many third-party libraries rely on pkg_resources internally. If setuptools is missing or damaged, importing pkg_resources fails, resulting in the following error:

ModuleNotFoundError: No module named 'pkg_resources'

Although developers rarely import pkg_resources directly, many popular libraries such as pip, virtualenv, pytest, and packaging tools depend on it behind the scenes.

What Causes “No Module Named ‘pkg_resources'”?

The error can occur for several reasons, ranging from missing packages to incorrect Python environments. Understanding the root cause makes troubleshooting much easier.

In most cases, reinstalling setuptools resolves the problem, but sometimes the issue lies with the virtual environment or interpreter configuration.

Missing setuptools

The most common cause is that setuptools is not installed.

Since pkg_resources is bundled with setuptools, removing or corrupting setuptools also removes access to pkg_resources.

This often happens after:

  • Fresh Python installations
  • Minimal Docker images
  • Br oken virtual environments
  • Manual package removal

Corrupted Python Environment

Sometimes setuptools is installed but its files become corrupted.

Interrupted package installations, accidental deletion of site-packages, or incompatible upgrades may leave Python unable to locate pkg_resources.

Reinstalling setuptools usually fixes the problem.

Wrong Python Interpreter

Many developers have multiple Python versions installed.

For example:

  • Python 3.10
  • Python 3.11
  • Anaconda
  • Virtual Environment

If setuptools is installed for one interpreter but the application runs using another, Python cannot find pkg_resources.

Virtual Environment Problems

Virtual environments isolate project dependencies.

If the environment is incomplete or missing setuptools, importing pkg_resources fails.

Recreating the virtual environment often solves the issue.

How to Fix ModuleNotFoundError: ‘pkg_resources’?

The best way to solve the error is to verify your Python environment first and then reinstall or upgrade setuptools if necessary.

Follow these troubleshooting steps in order.

Step 1: Check Your Python Version

Before installing anything, verify which Python interpreter is running.

Windows:

python --version

Linux/macOS:

python3 --version

You can also check the interpreter path:

python -c "import sys; print(sys.executable)"

This helps ensure you’re installing packages into the correct Python environment.

Step 2: Check Whether setuptools Is Installed

Run:

pip show setuptools

If installed, you’ll see output similar to:

Name: setuptools
Version: 75.0.0
Location: /usr/local/lib/python3.x/site-packages

If nothing is returned, setuptools is missing.

Step 3: Install or Reinstall setuptools

The most common solution is reinstalling setuptools.

pip install setuptools

To force a clean reinstall:

pip install --force-reinstall setuptools

Or upgrade to the latest version:

pip install --upgrade setuptools

Once installation completes, try running your program again.

Step 4: Verify the Module

Test whether Python can import pkg_resources.

python

Then run:

import pkg_resources
print(pkg_resources.__version__)

If no error appears, the module is working correctly.

Step 5: Upgrade pip

Older versions of pip sometimes install incompatible package versions.

Upgrade pip first:

python -m pip install --upgrade pip

Then upgrade setuptools again:

python -m pip install --upgrade setuptools

Keeping both tools updated prevents many dependency issues.

Step 6: Recreate the Virtual Environment

If the error occurs inside a virtual environment, recreate it.

Delete the environment:

rm -rf venv

Windows:

rmdir /s /q venv

Create a new environment:

python -m venv venv

Activate it:

Windows

venv\Scripts\activate

Linux/macOS

source venv/bin/activate

Install project dependencies:

pip install -r requirements.txt

This installs a fresh copy of setuptools and related packages.

Step 7: Verify the Correct Python Environment

Sometimes pip installs packages into one interpreter while the application runs with another.

Check installed packages:

python -m pip list

Instead of:

pip install setuptools

prefer:

python -m pip install setuptools

This ensures pip installs packages into the interpreter currently being used.

Fix the Error on Windows

Windows users commonly encounter this issue after installing multiple Python versions.

Verify Python:

where python

Install setuptools:
python -m pip install --upgrade setuptools

If using the Python Launcher:

py -m pip install setuptools

Restart Command Prompt after installation.

Fix the Error on macOS

macOS users should verify whether they’re using:

  1. System Python
  2. Homebrew Python
  3. pyenv
  4. Virtual Environment

Upgrade setuptools:

python3 -m pip install --upgrade setuptools

If using Homebrew:

brew update
brew upgrade python

Then reinstall setuptools.

Fix the Error on Linux

Linux distributions sometimes separate Python packages into system packages.

Ubuntu/Debian:

sudo apt update
sudo apt install python3-setuptools

Or install via pip:

python3 -m pip install setuptools

Common Scenarios That Trigger the Error

The error appears in many development workflows.

Understanding these situations helps identify the solution faster.

Running a Python Script

Example:

import pkg_resources

Output:

ModuleNotFoundError: No module named 'pkg_resources'

Installing setuptools resolves the issue.

Installing Python Packages

Sometimes pip itself throws:

ModuleNotFoundError: No module named 'pkg_resources'

Usually this indicates a broken setuptools installation.

Upgrade both pip and setuptools.

Using PyInstaller

Applications packaged with PyInstaller may fail if setuptools wasn’t included during packaging.

Reinstall setuptools before rebuilding the executable.

Running Flask or Django Projects

Framework dependencies may indirectly import pkg_resources.

If the virtual environment is incomplete, reinstall project dependencies:

pip install -r requirements.txt

Common Mistakes to Avoid

Many developers fix the wrong Python installation or accidentally mix package managers.

Avoid these common mistakes.

Installing Packages into the Wrong Interpreter

Running:

pip install setuptools

may install packages into a different Python version.

Instead use:

python -m pip install setuptools

Mixing System Python and Virtual Environments

Avoid installing project packages globally while running inside a virtual environment.

Always activate the virtual environment first.

Ignoring Version Compatibility

Very old versions of setuptools may not work correctly with newer Python releases.

Regularly update:

  1. Python
  2. pip
  3. setuptools

to maintain compatibility.

Deleting Site-Packages Manually

Avoid manually removing package folders.

Use pip instead:

pip uninstall setuptools

Then reinstall it.

How Moon Technolabs Helps with Python Development?

Moon Technolabs helps businesses build scalable Python applications, automation tools, APIs, AI solutions, and cloud-native platforms using modern development practices. Our Python experts troubleshoot dependency issues, optimize virtual environments, implement CI/CD pipelines, and ensure reliable package management across development and production environments.

Whether you’re developing web applications with Django or Flask, building machine learning solutions, or automating workflows with Python, Moon Technolabs delivers secure, maintainable, and high-performance solutions tailored to your business needs.

Facing Python Package or Dependency Errors?

Our Python experts help resolve package conflicts, dependency issues, and development challenges to build reliable, scalable, and high-performance applications.

Talk to Python Experts

Conclusion

The ModuleNotFoundError: No module named ‘pkg_resources’ error is usually caused by a missing or corrupted setuptools installation, an incorrect Python interpreter, or a broken virtual environment. While the error may seem intimidating, it is typically resolved by verifying your Python environment, reinstalling or upgrading setuptools, and ensuring packages are installed in the correct interpreter.

Following best practices such as using virtual environments, keeping pip and setuptools updated, and installing packages with python -m pip can prevent similar dependency issues in future projects. By understanding how Python manages packages and environments, developers can resolve this error quickly and maintain a more stable development workflow.

author image

Find comprehensive resources on Python programming, frameworks, automation, data science, AI, scripting, and backend development. Whether you're a beginner or an experienced developer, this category covers practical Python concepts and coding best practices. Stay updated with the latest Python tools, libraries, and development trends.

Related Q&A

bottom_top_arrow
Chat
Call Us Now
usa +1 (620) 330-9814
OR
+65
OR

You can send us mail

sales@moontechnolabs.com