How to fix "ImportError: No module named setuptools" on Linux

Last updated on September 23, 2020 by Dan Nanni

Question: I was trying to install a Python package using setup.py ("python setup.py install"). However, it failed with the following error message:
Traceback (most recent call last):
  File "setup.py", line 2, in 
    import setuptools
ImportError: No module named 'setuptools'
How can I fix this error?

There are several ways to package, distribute and install Python modules and programs. The most popular tools are distutils and setuptools. distutils is the standard Python packaging tool, while setuptools is a more feature-rich alternative to distutils. For example, unlike distutils, setuptools supports package dependency management, and can search for third-party modules in PyPi (Python Package Index). This makes setuptools more user-friendly.

When you install a Python application packaged with setuptools, you use the following command.

$ python (or python3) setup.py install

setup.py will then use setuptools module to retrieve and build the package as well as all dependent modules. Naturally, you must make sure that setuptools is available on your system. Without setuptools, you will encounter the error:

ImportError: No module named 'setuptools'

To fix this error, you need to install setuptools on your Linux system.

Install setuptools on Linux

To install setuptools on Debian, Ubuntu or Mint:

$ sudo apt-get install python-setuptools

For Python 3.X applications, install python3-setuptools instead.

$ sudo apt-get install python3-setuptools

On Red Hat based systems, setuptools comes pre-installed. For whatever reason if you want to install it, use the yum command.

$ sudo yum python-setuptools

Support Xmodulo

This website is made possible by minimal ads and your gracious donation via PayPal or credit card

Please note that this article is published by Xmodulo.com under a Creative Commons Attribution-ShareAlike 3.0 Unported License. If you would like to use the whole or any part of this article, you need to cite this web page at Xmodulo.com as the original source.

Xmodulo © 2021 ‒ AboutWrite for UsFeed ‒ Powered by DigitalOcean