Python 3: ImportError “No Module named Setuptools”

2019-01-02 20:01发布

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

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

importerror "No Module named Setuptools"

I have no idea what to do because I haven't have Setuptools never and still I have installed many packages with setup.py install command without setuptools and now I should get setuptools.

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

Why my install command doesn't work anymore?

7条回答
情到深处是孤独
2楼-- · 2019-01-02 20:39

pip uninstall setuptools

and then:

pip install setuptools

This works for me and fix my issue.

查看更多
弹指情弦暗扣
3楼-- · 2019-01-02 20:41

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 is probably obsolete (e.g. some links don't work).

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楼-- · 2019-01-02 20:47

Your setup.py file needs setuptools. Many of the Python packages use distutils for the distribution, but some use setuptools, a more complete package. Here is a question about the differences between them.

Regarding Python 3.3, you should install distribute instead. It is a more recent package that works in the same way as setuptools (it's even called setuptools internally).

UPDATE (Oct 2014): Distribute has been merged with setuptools 0.7, so just get setuptools for both Python 2.7 and 3.x

To install this on Debian:

sudo apt-get install python-setuptools

For Python 3.x

sudo apt-get install python3-setuptools
查看更多
骚的不知所云
5楼-- · 2019-01-02 20:47

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...
查看更多
还给你的自由
6楼-- · 2019-01-02 20:51

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. I know this question has already had an answer selected but I hope this answer will help others in my situation.

查看更多
像晚风撩人
7楼-- · 2019-01-02 20:51

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...
[~]
查看更多
登录 后发表回答