In this tutorial, you will learn about various methods and techniques you can use to fix this error.
What is Python setuptools?
Before you dive into what causes the “no module named ‘setuptools'” error, it is good to understand what are setuptools.
In Python, there are two main methods of building and distributing packages:
- Distutils
- Setuptools
Distutils is the default Python packaging tool. It is built into the Python standard library and hides the low-level details of building a Python package.
Setuptools on the other hand is an alternative to distutils. It is built on top of distutils and provides more features and enhancements compared to its counterpart.
Keep in mind that you will hardly differentiate between packages that are built with distutils and setuptools.
What Causes the “No Module Named ‘setuptools'” Error?
Nothing is more frustrating than running your code and getting an error as shown:
File " setup.py", line 1, in <module>
from setuptools import *
ModuleNotFoundError: No module named 'setuptoosl'
Although there is no universal cause of this type of error. There are three major possible causes. These include:
- Missing setuptools library
- Setuptools library not in the system path
- Incorrect Python and Pip Versions.
Let us discuss how we can attempt to resolve the error.
Solution #1 – Installing the setuptools Library
The major cause of the “no module named ‘setuptools’” error is the missing library. The setuptools package is not part of Python’s standard library. Hence, before importing it, it is good to ensure you have the package installed.
You can install the setuptools package by running the code shown below:
$ pip3 install setuptools
The command above will install the setuptools for your system. Ensure that you have pip installed on your system before running the code above.
On Linux systems, you may need to install the setuptools package using your package manager.
The commands for the popular Linux distributions are as provided below:
Debian/Ubuntu Based
Fedora/REHL
Arch/Manjaro Based
The commands above should download and install the Python setuptools utilities on your system.
Solution #2 – Include Setuptools in System Path.
In some cases, you may face the “no module named ‘setuptools'” even after installing the setuptools library.
This mainly occurs if pip is not available in your system’s path. You can fix this error by adding pip to path.
By default, the pip directory is located in:
C:\Users\username\anaconda3\pkgs\pip\Scripts
Note that the path may vary depending on the installation method and the Python interpreter installed.
Once you locate the path to pip, add it to your system path manually and refresh the terminal session to apply the changes.
You can then re-install the setuptools package using pip as shown in the command above.
Solution #3 – Incorrect Package
Another cause of this error is installing the package with the incorrect pip. To resolve this, ensure you have installed the setuptools with the pip for your Python interpreter.
For example, for Python3, install setuptools with the command:
For Python 2, run the command:
Closing
In this article, you learned about the possible causes of the ‘no module named ‘setuptools” in Python and how you can resolve it.