No module named ‘pkg_resources’ in Python may occur when you install a module or package your project. Follow the instructions below to find the root cause of this problem.
No module named ‘pkg_resources’ In Python
There are a lot of situations where you may see this error message:
from pkg_resources import load_entry_point ModuleNotFoundError: No module named 'pkg_resources'
Using pip to install a package is a common scenario. But others have also had the same problem when they run other Python applications like the build system Meson.
pkg_resources And Setuptools
With that message, Python is telling you that it couldn’t find the pkg_resources module.
It provides Python libraries with APIs to allow them to access resource files. Thanks to it, frameworks and extensible applications can discover plugins automatically. The module uses the “egg” format, which is similar to “gems” in Ruby and “jars” in Java.
However, you cannot install pkg_resources as a standalone module. It comes with the Setuptools library, which includes pkg_resources and a whole host of other tools for packaging in Python. To resolve the problem, you will need to install Setuptools.
The simplest way to install Setuptools is through the package manager pip:
pip install setuptools
Most of the time, your Python installation should already have pip. This is at least the case when you download it from the official website (python.org), use a virtual environment, or use a distribution where pip hasn’t been removed.
For data analysis and software development, using virtual environments is recommended. They isolate your projects from the system-wide Python installation.
The dependencies for each project will be kept in a single place and don’t get affected by changes you make elsewhere in the system. You can have different versions of the same Python module, making it easier to maintain and collaborate with people using other platforms.
You will need to create a virtual environment first with venv:
python -m venv learnshareit
Activate the virtual environment you want to work in:
Python will switch to the virtual environment and display its name in brackets on your console prompt. Now you can install setuptools:
(learnshareit) $ python -m pip install setuptools
Note: you can also use pip to solve errors such as “ModuleNotFoundError: no module named ‘requests’”.
If you don’t have pip on your system, you will need to install it first. There are various ways to do this.
The built-in ensurepip module of Python can help you download and set up pip in your environment. Depending on your operation system, use these commands on your terminal app:
Linux and macOS
python -m ensurepip --upgrade
py -m ensurepip --upgrade
The get-pip.py script is another popular method for installing pip. First, download it from https://bootstrap.pypa.io/get-pip.py, then run the script:
Linux and macOS
With Linux Package Managers
If you are using a popular Linux distribution, pip and setuptools are likely available on its package repository. They are officially distributed by developers of pip and setuptools. Their versions are usually out-of-date and may take some time to catch up with the latest version in upstream.
But official repositories are a nice way to incorporate your Python installation and modules into your Linux system. You can use its package manager to install, upgrade, and uninstall Python modules just as other packages.
Follow the instructions for your distribution.
sudo dnf install python3-pip
sudo zypper install python3-pip
sudo apt install python3-venv python3-pip
sudo pacman -S python-pip
The error No module named ‘pkg_resources’ in Python occurs when you don’t have the Setuptools library in your local Python installation. Use pip and your system’s package manager to install it to make the error disappear.
Maybe you are interested:
- TypeError: can only concatenate str (not “bytes”) to str
- ModuleNotFoundError: No module named ‘tensorflow’ in python
- How To ModuleNotFoundError: No Module Named ‘absl’ In Python
My name is Robert. I have a degree in information technology and two years of expertise in software development. I’ve come to offer my understanding on programming languages. I hope you find my articles interesting.
Name of the university: HUST