Python

No Module Named ‘setuptools’

Whether you are just getting started with Python or a seasoned pro, you will occasionally need to install external packages to use in your projects.However, in some cases, you may face the “No Module named ‘setuptools’ when attempting to install a specific package.

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:

  1. Distutils
  2. 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:

Traceback (most recent call last):

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:

  1. Missing setuptools library
  2. Setuptools library not in the system path
  3. 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:

$ pip install setuptools

$ 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

$ sudo apt-get install python3-setuptools -y

Fedora/REHL

$ sudo yum install python3-setuptools -y

Arch/Manjaro Based

$ sudo pacman -S python-setuptools

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\AppData\Local\Programs\Python310\Scripts

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:

$ pip3 install setuptools

For Python 2, run the command:

$ pip install setuptools

Closing

In this article, you learned about the possible causes of the ‘no module named ‘setuptools” in Python and how you can resolve it.

About the author

John Otieno

My name is John and am a fellow geek like you. I am passionate about all things computers from Hardware, Operating systems to Programming. My dream is to share my knowledge with the world and help out fellow geeks. Follow my content by subscribing to LinuxHint mailing list