Python 3:导入错误“没有名为 Setuptools 的模块”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14426491/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Python 3: ImportError "No Module named Setuptools"
提问by user1994934
I'm having troubles with installing packages in Python 3.
我在 Python 3 中安装软件包时遇到问题。
I have always installed packages with setup.py install. But now, when I try to install the ansicolors package I get:
我一直用setup.py install. 但是现在,当我尝试安装 ansicolors 包时,我得到:
importerror "No Module named Setuptools"
导入错误“没有名为 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 installwithout setuptools. Why should I get setuptools now?
我不知道该怎么做,因为我过去没有安装 setuptools。尽管如此,我还是能够在setup.py install没有 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 doesn't my install command work anymore?
为什么我的安装命令不再起作用?
采纳答案by tiago
Your setup.pyfile needs setuptools. Some Python packages used to use distutilsfor distribution, but most now use setuptools, a more complete package. Hereis a question about the differences between them.
您的setup.py文件需要setuptools. 一些 Python 包曾经distutils用于分发,但现在大多数使用setuptools,一个更完整的包。这是一个关于它们之间差异的问题。
To install setuptoolson Debian:
setuptools在 Debian 上安装:
sudo apt-get install python3-setuptools
For an older version of Python (Python 2.x):
对于旧版本的 Python (Python 2.x):
sudo apt-get install python-setuptools
回答by Blender
The distributepackage provides a Python 3-compatible version of setuptools: http://pypi.python.org/pypi/distribute
该distribute软件包提供了与 Python 3 兼容的版本setuptools:http: //pypi.python.org/pypi/distribute
Also, use pipto 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...
[~]
回答by Robert Lujo
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:
On Linux or OS X:
pip install -U pip setuptoolsOn Windows:
python -m pip install -U pip setuptools
如果您从 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
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:
Distribute- 是一个 setuptools fork,它“提供 Python 3 支持”。安装说明(setuptools)+ pip:
curl -O http://python-distribute.org/distribute_setup.py
python distribute_setup.py
easy_install pip
Similar issue here.
类似的问题在这里。
UPDATE: Distributeseems 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.
更新:Distribute似乎已过时,即合并到 Setuptools:Distribute 是 Setuptools 项目的弃用分支。自 Setuptools 0.7 版本以来,Setuptools 和 Distribute 已合并,不再维护 Distribute。所有正在进行的工作都应参考 Setuptools 项目和 Setuptools 文档。
You may try with instructionsfound 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
回答by Dawngerpony
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:
我在使用 python-2.6 的 Oracle Linux 6.4 上的 virtualenv 中执行此操作,因此基于 apt 的解决方案对我来说不是一个选择,python-2.7 的想法也不是。我的解决方法是升级我已由 virtualenv 安装的 setuptools 版本:
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 中。我知道这个问题已经有一个选择的答案,但我希望这个答案能帮助我的情况下的其他人。
回答by Cees Timmerman
The PyPA recommendedtool for installing and managing Python packages is pip. pipis included with Python 3.4 (PEP 453), but for older versions here's how to installit (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...
回答by Sathish
Windows 7:
Windows 7的:
I have given a complete solution herefor 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
回答by gonjay
pip uninstall setuptools
pip uninstall setuptools
and then:
进而:
pip install setuptools
pip install setuptools
This works for me and fix my issue.
这对我有用并解决了我的问题。
回答by Roger Vermeir
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
几年前,我继承了一个在 Django-1.2.3 下运行的 python (2.7.1) 项目,现在被要求用 QR 可能性来增强它。遇到了同样的问题,也没有找到 pip 或 apt-get 。所以我用一种完全不同但简单的方式解决了它。我 /bin/vi 编辑了 setup.py 并将“from setuptools import setup”这一行更改为:“from distutils.core import setup” 这对我来说是这样,所以我想我应该将其发布给其他运行旧 python 的用户. 问候,罗杰·维梅尔

