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

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

importerror "No Module named Setuptools"

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

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

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


当前回答

当我的pip requirements.txt文件包含一个使用诗词构建的可编辑库并包含一个pyproject时,我就遇到了这个问题。toml文件。遵循setuptools的文档,我的解决方案是将setuptools添加到pyproject中的构建系统需求中。Toml文件如下:

[build-system]
requires = ["poetry-core>=1.0.0", "setuptools"]
build-backend = "poetry.core.masonry.api"

其他回答

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

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

python -m pip install -U pip

在macOS上,如果你安装了自制程序,只需运行:

brew install rust

我在安装pyunicorn时遇到了这样的问题。我想在谷歌Colab上安装它。我试着直接从Github安装pyunicorn,它为我工作。以我为例,它是这样的:

pip install git+https://github.com/pik-copan/pyunicorn.git#egg=pyunicorn

PIP卸载setuptools

然后:

PIP安装setuptools

这对我有用,解决了我的问题。