Fix Python ModuleNotFoundError: No module named 'pkg_resources'

The ModuleNotFoundError: No module named 'pkg_resources' occurs in Python when the setuptools module can’t be found.

The full error message is as follows:

Traceback (most recent call last):
  File ...
    from pkg_resources import load_entry_point
ImportError: No module named pkg_resources

To fix this error, you need to install the setuptools module. This article will show simple steps you can do to troubleshoot this error.

How to fix this error

The pkg_resources module provides a set of APIs for Python libraries to access their resource files. This module is usually required when you install a certain package using pip.

Since the module is included in the setuptools package, you can try installing the package to fix this error:

pip install --upgrade setuptools
# or pip3:
pip3 install --upgrade setuptools

If you still see the error, then try uninstalling setuptools first:

pip uninstall -y setuptools

# then install again
pip install setuptools

If the command above doesn’t work, try upgrading pip, setuptools, and wheel to the latest version:

# For Unix/ macOS:
python3 -m pip install --upgrade pip setuptools wheel

# For windows:
py -m pip install --upgrade pip setuptools wheel

As an alternative, you can also try to create a virtual environment using the venv module.

The venv module is included in Python 3, and you can create a new virtual environment by running the commands below:

# For Unix/ macOS:
python3 -m venv my_env
source my_env/bin/activate

# For Windows:
py -m venv my_env
my_env\Scripts\activate

Once the virtual environment is activated, install the latest versions of pip, setuptools, and wheel package first.

Now that you have the setuptools in the virtual environment try installing and running the command that causes the No module named pkg_resources error.

Conclusion

The ModuleNotFoundError: No module named 'pkg_resources' error happens when Python can’t find the pkg_resources module, which is required by the command you’re running.

To fix this error, you need to ensure that you have the latest version of setuptools package installed on your system.

This article shows you how to upgrade or reinstall the setuptools package. Cheers! 🙌

Take your skills to the next level ⚡️

I'm sending out an occasional email with the latest tutorials on programming, web development, and statistics. Drop your email in the box below and I'll send new stuff straight into your inbox!

No spam. Unsubscribe anytime.