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

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

importerror "No Module named Setuptools"

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

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

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


当前回答

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

其他回答

我运行sudo python setup.py build_ext -i,它失败了,没有名为setuptools的模块。

我用这个命令解决了这个问题:

<i>sudo apt-get install python-setuptools</i>

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

如果pip没有安装,比如它来自死蛇PPA,或者Docker环境,修复此错误的最佳方法是通过运行引导它

python -m ensurepip

当有pyproject的时候。Toml和setup.py在同一个目录下,它可能是问题的原因。我重命名了该文件,但它没有解决问题,所以我重新建立了原来的文件名,并进行了以下更改。

在[build-system]部分下,我将“setuptools”添加到requires=列表中,它起作用了。

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