Python 3: ImportError“没有一个名为Setuptools的模块”

时间:2020-12-21 18:04:27

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

我在Python 3中安装包遇到了麻烦。

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

我总是安装有设置的包。py安装命令。但是现在,当我尝试安装ansicolors包时,我得到:

importerror "No Module named Setuptools"

importerror“没有一个名为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.

我不知道该怎么做,因为我没有Setuptools,而且我已经安装了很多安装包。py安装命令没有setuptools,现在我应该得到setuptools。

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

我甚至不能安装setuptools,因为我有python 3.3和setuptools不支持python 3。

Why my install command doesn't work anymore?

为什么我的安装命令不再起作用了?

7 个解决方案

#1


223  

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.

你的设置。py文件需要setuptools。许多Python包使用distutils进行分发,但是有些包使用setuptools,一个更完整的包。这里有一个关于他们之间的区别的问题。

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).

对于Python 3.3,您应该安装分发版本。它是一个与setuptools(它甚至在内部称为setuptools)相同的方式工作的最新包。

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

更新(2014年10月):发布与setuptools 0.7合并,所以只需要为Python 2.7和3.x提供setuptools。

To install this on Debian:

在Debian上安装这个:

sudo apt-get install python-setuptools

For Python 3.x

对于Python 3. x

sudo apt-get install python3-setuptools

#2


53  

EDIT: Official setuptools dox page:

编辑:官方的setuptools dox页:

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:

如果您有Python 2 >=2.7.9或Python 3 >=3.4安装在python.org上,您将已经有了pip和setuptools,但是需要升级到最新版本:

On Linux or OS X:

在Linux或OS X上:

pip install -U pip setuptools 

On Windows:

在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:

分发-是一个setuptools分支,它“提供Python 3支持”。安装说明(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.

更新:分发似乎过时了,即合并到Setuptools:分发是Setuptools项目的一个废弃的分支。自从Setuptools 0.7发布以来,Setuptools和分发已经不再被维护了。所有正在进行的工作都应该引用Setuptools项目和Setuptools文档。

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

您可以尝试使用setuptools pypi页面上的指示(我还没有测试这个,对不起:():

wget https://bitbucket.org/pypa/setuptools/raw/bootstrap/ez_setup.py -O - | python
easy_install pip

#3


17  

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:

我是在Oracle Linux 6.4的virtualenv中使用python-2.6做这个的,所以基于api的解决方案不是我的选择,python-2.7的想法也不是。我的解决方案是升级我的setuptools,它是由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.

在那之后,我就可以将包安装到virtualenv中了。我知道这个问题已经有答案了,但我希望这个答案能帮助我的处境中的其他人。

#4


4  

pip uninstall setuptools

皮普卸载setuptools

and then:

然后:

pip install setuptools

pip安装setuptools

This works for me and fix my issue.

这对我很有效,也解决了我的问题。

#5


3  

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

分发包提供了一个Python 3兼容版本的setuptools: http://pypi.python.org/pypi/distribute。

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

另外,使用pip来安装模块。它会自动发现依赖关系并为您安装它们。

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

#6


2  

Windows 7:

Windows 7:

I have given a complete solution here for python selenium webdriver

我已经为python selenium webdriver提供了一个完整的解决方案。

1. Setup easy install (windows - simplified)
    a. download ez.setup.py (https://bootstrap.pypa.io/ez_setup.py) from 'https://pypi.python.org/pypi/setuptools'
    b. move ez.setup.py to C:\Python27\
    c. open cmd prompt
    d. cd C:\Python27\
    e. C:\Python27\python.exe ez.setup.py install

#7


0  

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):

PyPA推荐用于安装和管理Python包的工具是pip。pip包含在Python 3.4 (PEP 453)中,但是对于老版本来说,如何安装它(在Windows上):

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

下载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...

#1


223  

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.

你的设置。py文件需要setuptools。许多Python包使用distutils进行分发,但是有些包使用setuptools,一个更完整的包。这里有一个关于他们之间的区别的问题。

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).

对于Python 3.3,您应该安装分发版本。它是一个与setuptools(它甚至在内部称为setuptools)相同的方式工作的最新包。

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

更新(2014年10月):发布与setuptools 0.7合并,所以只需要为Python 2.7和3.x提供setuptools。

To install this on Debian:

在Debian上安装这个:

sudo apt-get install python-setuptools

For Python 3.x

对于Python 3. x

sudo apt-get install python3-setuptools

#2


53  

EDIT: Official setuptools dox page:

编辑:官方的setuptools dox页:

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:

如果您有Python 2 >=2.7.9或Python 3 >=3.4安装在python.org上,您将已经有了pip和setuptools,但是需要升级到最新版本:

On Linux or OS X:

在Linux或OS X上:

pip install -U pip setuptools 

On Windows:

在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:

分发-是一个setuptools分支,它“提供Python 3支持”。安装说明(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.

更新:分发似乎过时了,即合并到Setuptools:分发是Setuptools项目的一个废弃的分支。自从Setuptools 0.7发布以来,Setuptools和分发已经不再被维护了。所有正在进行的工作都应该引用Setuptools项目和Setuptools文档。

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

您可以尝试使用setuptools pypi页面上的指示(我还没有测试这个,对不起:():

wget https://bitbucket.org/pypa/setuptools/raw/bootstrap/ez_setup.py -O - | python
easy_install pip

#3


17  

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:

我是在Oracle Linux 6.4的virtualenv中使用python-2.6做这个的,所以基于api的解决方案不是我的选择,python-2.7的想法也不是。我的解决方案是升级我的setuptools,它是由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.

在那之后,我就可以将包安装到virtualenv中了。我知道这个问题已经有答案了,但我希望这个答案能帮助我的处境中的其他人。

#4


4  

pip uninstall setuptools

皮普卸载setuptools

and then:

然后:

pip install setuptools

pip安装setuptools

This works for me and fix my issue.

这对我很有效,也解决了我的问题。

#5


3  

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

分发包提供了一个Python 3兼容版本的setuptools: http://pypi.python.org/pypi/distribute。

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

另外,使用pip来安装模块。它会自动发现依赖关系并为您安装它们。

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

#6


2  

Windows 7:

Windows 7:

I have given a complete solution here for python selenium webdriver

我已经为python selenium webdriver提供了一个完整的解决方案。

1. Setup easy install (windows - simplified)
    a. download ez.setup.py (https://bootstrap.pypa.io/ez_setup.py) from 'https://pypi.python.org/pypi/setuptools'
    b. move ez.setup.py to C:\Python27\
    c. open cmd prompt
    d. cd C:\Python27\
    e. C:\Python27\python.exe ez.setup.py install

#7


0  

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):

PyPA推荐用于安装和管理Python包的工具是pip。pip包含在Python 3.4 (PEP 453)中,但是对于老版本来说,如何安装它(在Windows上):

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

下载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...