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

我总是用setup.py install安装包。但是现在,当我尝试安装anicolors包时,我得到:

importerror "No Module named Setuptools"

我不知道该怎么做,因为我过去没有安装安装工具。尽管如此,我仍然能够使用setup.py install安装许多包,而不需要setuptools。为什么我现在要安装工具?

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

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


当前回答

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

其他回答

几年前,我继承了一个在Django-1.2.3下运行的Python(2.7.1)项目,现在被要求用QR可能性来增强它。我遇到了同样的问题,也没有找到pip或apt-get。所以我用一种完全不同但简单的方法解决了它。

我/bin/vi了setup.py并更改了行 从setuptools导入 成: “从distutils。核心导入设置”

Windows 7:

我在这里给出了Python Selenium WebDriver的完整解决方案:

安装简单(Windows -简化) 从“https://pypi.python.org/pypi/setuptools”下载ez.setup.py (https://bootstrap.pypa.io/ez_setup.py) 将ez.setup.py移到C:\Python27\ 打开CMD提示符 cd C: \ Python27 \ C:\Python27\python.exe ez.setup.py安装

分发包提供了与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...
[~]

我的解决方案是升级我的setuptools:

python3 -m pip install --upgrade pip setuptools wheel

在Debian上工作,有时可能是因为旧的pip版本。因此,更新pip>

python -m pip install -U pip