问题:Python 3:ImportError“没有名为Setuptools的模块”
我在使用Python 3安装软件包时遇到了麻烦。
我一直都使用来安装软件包setup.py install
。但是现在,当我尝试安装ansicolors软件包时,我得到了:
importerror“没有名为Setuptools的模块”
我不知道该怎么办,因为过去我没有安装过setuptools。尽管如此,我仍然能够在setup.py install
没有setuptools的情况下安装许多软件包。为什么现在应该获得setuptools?
我什至无法安装setuptools,因为我有Python 3.3,setuptools不支持Python 3。
为什么我的安装命令不再起作用?
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?
回答 0
您的setup.py
文件需要setuptools
。一些Python软件包曾经distutils
用于分发,但现在大多数都使用setuptools
了一个更完整的软件包。这是有关它们之间差异的问题。
要setuptools
在Debian上安装:
sudo apt-get install python3-setuptools
对于旧版本的Python(Python 2.x):
sudo apt-get install python-setuptools
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
回答 1
编辑:官方setuptools dox页面:
如果您从python.org安装了Python 2> = 2.7.9或Python 3> = 3.4,则已经具有pip和setuptools,但需要升级到最新版本:
在Linux或OS X上:
pip install -U pip setuptools
在Windows上:
python -m pip install -U pip setuptools
因此,本文的其余部分可能已过时(例如,某些链接不起作用)。
分发 -是setuptools分支,可“提供Python 3支持”。Distribution(setuptools)+ pip的安装说明:
curl -O http://python-distribute.org/distribute_setup.py
python distribute_setup.py
easy_install pip
这里有类似的问题。
更新:分发似乎已过时,即已合并到Setuptools中:分发是Setuptools项目不推荐使用的分支。从Setuptools 0.7发行版开始,Setuptools和Distribute已合并,并且不再维护Distribute。所有正在进行的工作应参考Setuptools项目和Setuptools文档。
您可以尝试在setuptools pypi页面上找到说明(我尚未对此进行测试,对不起:():
wget https://bitbucket.org/pypa/setuptools/raw/bootstrap/ez_setup.py -O - | python
easy_install pip
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
回答 2
我在使用python-2.6的Oracle Linux 6.4上的virtualenv内执行此操作,因此基于apt的解决方案对我来说不是一个选择,python-2.7的想法也不对。我的解决方法是升级我由virtualenv安装的setuptools版本:
pip install --upgrade setuptools
之后,我能够将软件包安装到virtualenv中。我知道这个问题已经选择了答案,但我希望这个答案对我的情况有所帮助。
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.
回答 3
pip uninstall setuptools
然后:
pip install setuptools
这对我有用,并解决了我的问题。
pip uninstall setuptools
and then:
pip install setuptools
This works for me and fix my issue.
回答 4
该distribute
软件包提供了与Python 3兼容的版本setuptools
:http : //pypi.python.org/pypi/distribute
另外,用于pip
安装模块。它会自动找到依赖项并为您安装它们。
对于您的包裹,它对我来说效果很好:
[~] 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...
[~]
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...
[~]
回答 5
Windows 7的:
我在这里为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
Windows 7:
I have given a complete solution here for 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
回答 6
该PyPA推荐的用于安装和管理Python包的工具pip
。pip
包括在Python 3.4(PEP 453),但对于旧版本这里是如何安装它(在Windows上):
下载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...
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...
回答 7
几年前,我继承了在Django-1.2.3下运行的python(2.7.1)项目,现在被要求使用QR增强功能。遇到了同样的问题,没有找到pip或apt-get。所以我以完全不同但简单的方式解决了它。我/ bin / vi-ed setup.py,并将“ from setuptools import setup”这一行更改为:“ from distutils.core import setup”对我而言,所以我认为我应该将它发布给其他运行旧python的用户。问候,罗杰·维米尔
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. 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”
That did it for me, so I thought I should post this for other users running old pythons.
Regards,
Roger Vermeir