PIP安装可编辑错误:模块未找到setuptools



我有一个包,我已经在其他机器上安装了很多次,但在我的Mac上,我得到一个奇怪的错误。我试过在conda环境和虚拟环境中这样做,总是得到下面相同的错误。

注意:

  • 我可以打开python shell并导入setuptools而不会出现问题。
  • 没有-e
  • 它列出了失败的命令,我可以手动运行。我已经通过pip升级了setuptools
/Users/eric/Library/Caches/pypoetry/virtualenvs/mypkg-3XmClfyY-py3.9/bin/pip install -e ~/Documents/MyDir/repo/mypkg
Obtaining file:///Users/eric/Documents/MyDir/repo/mypkg
Installing build dependencies ... done
Getting requirements to build wheel ... done
Preparing wheel metadata ... done
Requirement already satisfied: loguru<0.6.0,>=0.5.3 in /Users/eric/Library/Caches/pypoetry/virtualenvs/mypkg-3XmClfyY-py3.9/lib/python3.9/site-packages (from mypkg==0.1.0) (0.5.3)
Installing collected packages: mypkg
Running setup.py develop for mypkg
ERROR: Command errored out with exit status 1:
command: /Users/eric/Library/Caches/pypoetry/virtualenvs/mypkg-3XmClfyY-py3.9/bin/python -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/Users/eric/Documents/MyDir/repo/mypkg/setup.py'"'"'; __file__='"'"'/Users/eric/Documents/MyDir/repo/mypkg/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'rn'"'"', '"'"'n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' develop --no-deps
cwd: /Users/eric/Documents/MyDir/repo/mypkg/
Complete output (7 lines):
Traceback (most recent call last):
File "<string>", line 1, in <module>
import io, os, sys, setuptools, tokenize; sys.argv[0] = '/Users/eric/Documents/MyDir/repo/mypkg/setup.py'; __file__='/Users/eric/Documents/MyDir/repo/mypkg/setup.py';f = getattr(tokenize, 'open', open)(__file__) if os.path.exists(__file__) else io.StringIO('from setuptools import setup; setup()');code = f.read().replace('rn', 'n');f.close();exec(compile(code, __file__, 'exec'))
│                                                                                                                                                                            │                             └ <module 'io' from '/usr/local/Cellar/python@3.9/3.9.5/Frameworks/Python.framework/Versions/3.9/lib/python3.9/io.py'>
│                                                                                                                                                                            └ <module 'os' from '/usr/local/Cellar/python@3.9/3.9.5/Frameworks/Python.framework/Versions/3.9/lib/python3.9/os.py'>
└ <module 'sys' (built-in)>
ModuleNotFoundError: No module named 'setuptools'
----------------------------------------
ERROR: Command errored out with exit status 1: /Users/eric/Library/Caches/pypoetry/virtualenvs/mypkg-3XmClfyY-py3.9/bin/python -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/Users/eric/Documents/MyDir/repo/mypkg/setup.py'"'"'; __file__='"'"'/Users/eric/Documents/MyDir/repo/mypkg/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'rn'"'"', '"'"'n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' develop --no-deps Check the logs for full command output.

我的问题在pyproject.toml。我没有意识到皮普正在看(虽然现在看起来很明显)。

问题是这样的,当我配置诗歌:

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

您的setup.py文件需要setuptools。一些Python包过去使用distutils进行分发,但现在大多数使用setuptools,这是一个更完整的包。这是一个关于它们之间区别的问题。

在Debian安装setuptools:

sudo apt-get install python3-setuptools

对于旧版本的Python (Python 2.x):

sudo apt-get install python-setuptools

然后检查你的虚拟环境。