The “pkg_resources” module enables access to the resource files for Python Library. It is quite useful for finding and managing Python versions/packages with all their dependencies. While dealing with Python libraries, an error “no module named pkg_resources” occurs in the terminal.
This article will provide multiple solutions to encounter the above-stated error. The content of the guide is as follows:
- Reason 1: Broken “pkg_resources” Module
- Solution: Install “pkg_resources” Module
- Reason 2: Not Installed “setuptools” in Python Environment
- Solution: Install “setuptools” using pip Package Manager
Let’s start with the first reason.
Reason 1: Broken “pkg_resources” Module
Some files of the “pkg_resources” module are not properly integrated into the Python environment. Therefore, during the installation of any package, the resource files are not accessible to the installed Python environment.
Solution: Install the “pkg_resources” Module
To encounter the above-stated error is to install the “pkg_resources” package. It automatically installs all the required dependencies for the python environment. To do so, the below script will install the “pkg_resources” in the operating system:
$ sudo apt install python-pkg-resources
After executing the command, all required dependent files are installed in the operating system.
Reason 2: Not Installed “setuptools” in Python Environment
One of the prominent reasons for causing the error is that “setuptools” is not installed in the current python environment. The pkg_resources are equipped in the “setuptools” package. Therefore, the “pkg_resources” are not accessible in the operating system.
Solution: Install the “setuptools” Package
One of the solutions is to install the “setuptools” from the pip package manager to resolve errors. To do so, first install pip on your respective Linux distribution:
$ sudo apt install python3-pip
All dependencies that are required for the python environment is installed in the current system.
To install the “setuptools” package from the pip package manager, execute the below script:
$ pip install setuptools
The output shows that “setup-tools” packages have been installed in the system.
These are all the possible reasons and their relevant solutions.
Conclusion
The error “no module named pkg_resources” comes across due to the unavailability of “setuptools” in the Python environment. The error can be resolved by installing the python package via “sudo apt install python-pkg-resources”. Alternatively, the “sudo pip3 install setuptools” command installs the setup tools that meet the requirement of “pkg-resources”. This guide has explained all possible methods to encounter the error as mentioned above.