447

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?

24 Answers 24

723

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
9
  • 1
    thanks for this post.. helped me a lot..Many peoples are advicing setuptools but its not possible to instal in py3.3..the distribute works like a charm Commented May 18, 2013 at 13:31
  • 28
    i had to install it with "python3" to get it work: sudo apt-get install python3-setuptools
    – D.Steinel
    Commented Jan 8, 2014 at 13:02
  • 2
    I installed python3 python3-pip python3-setuptools and it worked. Thanks.
    – warchantua
    Commented Sep 5, 2017 at 10:07
  • 12
    For some reason in Ubuntu 18.04 it does not work with apt-get install python3-setuptools. Commented Apr 4, 2019 at 8:17
  • 8
    I used pip3 install setuptools.
    – egelev
    Commented Mar 30, 2020 at 9:37
203

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
4
  • 2
    Thank you so much, I'm not sure how this solved my problem but it did. instantly! I was having serious issues trying to install distribute. this must have somehow forced the install as sudo pip install distribute would not work. My issues are documented at stackoverflow.com/questions/16846742/…
    – Deepend
    Commented May 30, 2013 at 23:12
  • 2
    This works cross-platform (Win), whereas the accepted answer is not applicable. Thanks!
    – fundead
    Commented Mar 25, 2014 at 22:25
  • 1
    URLS are not longer valid .. could you please check ?
    – mebada
    Commented Jun 13, 2017 at 10:27
  • This worked for me, while the accepted answer ended up in broken python distribution after installing certain packages afterwards. Commented Aug 10, 2021 at 17:01
66

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
2
  • 2
    Solved the issue just by upgrading pip using "pip3 install -U pip ". Thanks mate!
    – justudin
    Commented Mar 4, 2021 at 4:24
  • Of all the solutions, this is the one that worked. Commented May 24, 2021 at 13:09
40

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.

1
  • 2
    Note, it had trouble "Cannot remove entries from nonexistent file..." Adding --ignore-installed to the above command fixed that. Commented Mar 15, 2018 at 20:55
36

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

python3 -m pip install --upgrade pip setuptools wheel
0
32

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.

4
  • 5
    This just solved all my lifes problems. Can confirm this works. Thans Jan! Commented Jan 27, 2021 at 16:07
  • Because pip looks into pyproject.toml (as setup.py and other files) as project configuration place.
    – ColCh
    Commented Sep 1, 2021 at 20:59
  • 1
    I am having no issues with having both config files in the projects I work with, upgrading pip and installing setuptools was enough.
    – m-dz
    Commented Jan 21, 2022 at 10:56
  • THank you so much!!! Was pulling my hair out trying to debug this. Python is great but packaging makes me want to scream.
    – 1110101001
    Commented Jan 22, 2023 at 9:34
16

pip uninstall setuptools

and then:

pip install setuptools

This works for me and fixes my issue.

4
  • This worked for me! Somehow my setuptools was older version 28.8. This uninstall and reinstall forced it to update to version 48. And then everything worked fine.
    – jlee88my
    Commented Aug 24, 2019 at 19:46
  • In my case, two different versions of setuptools were installed for some reason. Discovered it when I tried pip uninstall
    – Safwan
    Commented Aug 31, 2020 at 8:07
  • pip install --upgrade setuptools also does the trick Commented Aug 31, 2020 at 23:36
  • This works because it installs a later version of setuptools Commented Jul 19, 2022 at 9:44
13

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!
13

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.

1
  • this worked for me - i was tearing my hair out. thank you. Commented Oct 18, 2021 at 16:03
9

this is how my problem was solved => pip3 install setuptools-rust

If you want to check your list => pip3 list

i faced this problem while trying to install elastalert2

System informations

CentOS Linux release 7.9.2009 (Core)

Python 3.6.8

pip 21.3.1 from /usr/local/lib/python3.6/site-packages/pip (python 3.6)

2
  • 1
    This is exactly the solution. I switched to torch_mps and in order to install transformer it requires rust to compile the tokenizer.
    – Lei Zhang
    Commented Aug 10, 2022 at 9:54
  • Happy to hear its working :) Commented Aug 16, 2022 at 10:11
7

I ran into this problem when my pip requirements.txt file contained an editable library that was built using poetry and contained a pyproject.toml file. Following the documentation for setuptools, my solution was to add setuptools to the build-system requirements in the pyproject.toml file as follows:

[build-system]
requires = ["poetry-core>=1.0.0", "setuptools"]
build-backend = "poetry.core.masonry.api"
5

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...
[~]
4

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
4

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>
0
3

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
2

A few years ago I inherited a Python (2.7.1) project running under Django-1.2.3 and now was asked to enhance it with QR possibilities. I got the same problem and did not find pip or apt-get either. So I solved it in a totally different, but easy way.

I /bin/vi-ed the setup.py and changed the line "from setuptools import setup" into: "from distutils.core import setup"

1

The PyPA recommended tool for installing and managing Python packages is pip. pip is included with Python 3.4 (PEP 453), but for older versions here's how to install it (on Windows):

Download https://bootstrap.pypa.io/get-pip.py

>c:\Python33\python.exe get-pip.py
Downloading/unpacking pip
Downloading/unpacking setuptools
Installing collected packages: pip, setuptools
Successfully installed pip setuptools
Cleaning up...

>c:\Python33\Scripts\pip.exe install pymysql
Downloading/unpacking pymysql
Installing collected packages: pymysql
Successfully installed pymysql
Cleaning up...
0

If you still find this issue, try this:

python3 -m pip install scrapy --upgrade --force --user
0

While trying to install socketIO I had the same issue. At my system (Windows 11) setupTools were there twice. At C:\Program Files\Python310\Lib\site-packages\ and at C:\Users\user\AppData\Roaming\Python\Python310\site-packages\ Had to uninstall one of them.

0

On macOS, if you have homebrew installed, simply run:

brew install rust
0

Working on Debian, sometime it can be because of older pip version. Therefore, update pip>

python -m pip install -U pip

0

I had such a problem to install pyunicorn. I wanted to install it on Google Colab. I tried installing pyunicorn directly from Github and it worked for me. For example in my case it was like this:

pip install git+https://github.com/pik-copan/pyunicorn.git#egg=pyunicorn
-2

If you using poetry to manage your virtual environment, have poetry upgrade your version of setuptools:

poetry update

Note: Specifying poetry update setuptools might not work for you, since setuptools may not be an explicit dependency.

-3

Try installing the same using python==3.7.6

It worked for me.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.