Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python 3: ImportError "No Module named Setuptools"

I'm having troubles with installing packages in Python 3.

I have always installed packages with setup.py install. But now, when I try to install the ansicolors package I get:

importerror "No Module named Setuptools"

I have no idea what to do because I didn't have setuptools installed in the past. Still, I was able to install many packages with setup.py install without setuptools. Why should I get setuptools now?

I can't even install setuptools because I have Python 3.3 and setuptools doesn't support Python 3.

Why doesn't my install command work anymore?

like image 398
user1994934 Avatar asked Jan 20 '13 16:01

user1994934


People also ask

How do I fix Importerror No module named Setuptools?

The most likely reason is that Python doesn't provide setuptools in its standard library. You need to install it first! Before being able to import the Pandas module, you need to install it using Python's package manager pip . Make sure pip is installed on your machine.

How do I import Setuptools in Python?

Follow the below steps to install the Setuptools package on Linux using the setup.py file: Step 1: Download the latest source package of Setuptools for Python3 from the website. Step 3: Go to the setuptools-60.5. 0 folder and enter the following command to install the package.


13 Answers

Your setup.py file needs setuptools. Some Python packages used to use distutils for distribution, but most now use setuptools, a more complete package. Here is a question about the differences between them.

To install setuptools on Debian:

sudo apt-get install python3-setuptools

For an older version of Python (Python 2.x):

sudo apt-get install python-setuptools
like image 131
tiago Avatar answered Oct 13 '22 07:10

tiago


EDIT: Official setuptools dox page:

If you have Python 2 >=2.7.9 or Python 3 >=3.4 installed from python.org, you will already have pip and setuptools, but will need to upgrade to the latest version:

On Linux or OS X:

pip install -U pip setuptools 

On Windows:

python -m pip install -U pip setuptools

Therefore the rest of this post related to Distribute is obsolete (e.g. some links don't work).

EDIT 2022-02-04

From Python 3.10 Distutils is deprecated and will be removed in Python 3.12 - use setuptools:

The entire distutils package is deprecated, to be removed in Python 3.12. Its functionality for specifying package builds has already been completely replaced by third-party packages setuptools and packaging ...

Distribute (deprecated)

Distribute - is a setuptools fork which "offers Python 3 support". Installation instructions for distribute(setuptools) + pip:

curl -O http://python-distribute.org/distribute_setup.py
python distribute_setup.py
easy_install pip

Similar issue here.

UPDATE: Distribute seems to be obsolete, i.e. merged into Setuptools: Distribute is a deprecated fork of the Setuptools project. Since the Setuptools 0.7 release, Setuptools and Distribute have merged and Distribute is no longer being maintained. All ongoing effort should reference the Setuptools project and the Setuptools documentation.

You may try with instructions found on setuptools pypi page (I haven't tested this, sorry :( ):

wget https://bitbucket.org/pypa/setuptools/raw/bootstrap/ez_setup.py -O - | python
easy_install pip
like image 45
Robert Lujo Avatar answered Oct 13 '22 08:10

Robert Lujo


Make sure you are running the latest version of pip

I tried to install Ansible and it failed with

ModuleNotFoundError: No module named 'setuptools_rust'

python3-setuptools was already in place, so upgrading pip solved it.

pip3 install -U pip
like image 30
Bjarte Brandt Avatar answered Oct 13 '22 06:10

Bjarte Brandt


I was doing this inside a virtualenv on Oracle Linux 6.4 using Python 2.6, so the apt-based solutions weren't an option for me, nor were the Python 2.7 ideas. My fix was to upgrade my version of setuptools that had been installed by virtualenv:

pip install --upgrade setuptools

After that, I was able to install packages into the virtualenv.

like image 45
Dawngerpony Avatar answered Oct 13 '22 06:10

Dawngerpony


The solution which worked for me was to upgrade my setuptools:

python3 -m pip install --upgrade pip setuptools wheel
like image 21
Yaakov Bressler Avatar answered Oct 13 '22 06:10

Yaakov Bressler


For others with the same issue due to a different reason: This can also happen when there's a pyproject.toml in the same directory as the setup.py, even when setuptools is available.

Removing pyproject.toml fixed the issue for me.

like image 21
Jan Rüegg Avatar answered Oct 13 '22 07:10

Jan Rüegg


pip uninstall setuptools

and then:

pip install setuptools

This works for me and fixes my issue.

like image 39
gonjay Avatar answered Oct 13 '22 06:10

gonjay


First step #1
You have to install setuptools

On Linux:

pip install -U pip setuptools

On Mac OS:

pip install -U pip setuptools

On Windows:

python -m pip install -U pip setuptools

Second step #2

Make sure you have made it accessible (make it available in environmental variables)

On Linux

export PATH="INSTALLATIONDIRECTORY:$PATH"

On Mac OS

Sorry, I don't know.

On Windows

  1. Open the Start Search, type in “env”, and choose “Edit the system environment variables”
  2. Click the “Environment Variable” button.
  3. Set the environment variables as needed. The New button adds an additional variable.
  4. Dismiss all of the dialogs by choosing “OK”. Your changes are saved!
like image 34
Rohit Nishad Avatar answered Oct 13 '22 08:10

Rohit Nishad


When there's a pyproject.toml in the same directory as the setup.py, it can be the cause of the issue. I renamed that file, but it didn't solve the issue, so I restablished the original file name, and did the following change.

Under the [build-system] section, I added "setuptools" to the requires= list, and it worked.

like image 45
Lucioric2000 Avatar answered Oct 13 '22 08:10

Lucioric2000


The distribute package provides a Python 3-compatible version of setuptools: http://pypi.python.org/pypi/distribute

Also, use pip to install the modules. It automatically finds dependencies and installs them for you.

It works just fine for me with your package:

[~] pip --version                                                              
pip 1.2.1 from /usr/lib/python3.3/site-packages (python 3.3)
[~] sudo pip install ansicolors                                                
Downloading/unpacking ansicolors
  Downloading ansicolors-1.0.2.tar.gz
  Running setup.py egg_info for package ansicolors

Installing collected packages: ansicolors
  Running setup.py install for ansicolors

Successfully installed ansicolors
Cleaning up...
[~]
like image 20
Blender Avatar answered Oct 13 '22 06:10

Blender


If pip isn't installed, like for example if it's coming from the Deadsnakes PPA, or a Docker environment, the best way to fix this error is by bootstrapping it by running

python -m ensurepip
like image 37
CharlesB Avatar answered Oct 13 '22 06:10

CharlesB


Windows 7:

I have given a complete solution here for Python Selenium WebDriver:

  1. Setup easy install (Windows - simplified)
    1. download ez.setup.py (https://bootstrap.pypa.io/ez_setup.py) from 'https://pypi.python.org/pypi/setuptools'
    2. move ez.setup.py to C:\Python27\
    3. open cmd prompt
    4. cd C:\Python27\
    5. C:\Python27\python.exe ez.setup.py install
like image 31
Sathish Avatar answered Oct 13 '22 08:10

Sathish


I ran sudo python setup.py build_ext -i and it failed with No module named setuptools.

I solved it with this command:

<i>sudo apt-get install python-setuptools</i>
like image 24
Sheldon Avatar answered Oct 13 '22 07:10

Sheldon