python
module_error
ai_generated
true
错误:文件 "setup.py",第 1 行 from setuptools import setup ModuleNotFoundError:没有名为 'setuptools' 的模块
ERROR: File "setup.py", line 1, in <module> from setuptools import setup ModuleNotFoundError: No module named 'setuptools'
ID: python/pip-legacy-editable-develop-error
80%修复率
87%置信度
0证据数
2024-02-14首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 3.x | active | — | — | — |
根因分析
构建环境(通常是隔离的 PEP 517 环境或全新的 venv)未安装 setuptools,而项目的 setup.py 无条件导入它。
English
The build environment (often an isolated PEP 517 env or a fresh venv) does not have setuptools installed, and the project's setup.py imports it unconditionally.
解决方案
-
95% 成功率
Add a build-system table to pyproject.toml: [build-system]\nrequires = ["setuptools>=61", "wheel"]\nbuild-backend = "setuptools.build_meta"
-
85% 成功率
Install with build isolation disabled: pip install --no-build-isolation .
-
90% 成功率
Install setuptools in the active venv then run pip install -e . --no-build-isolation
无效尝试
常见但无效的做法:
-
90% 失败
setup.py must be evaluated before install_requires is processed, so the import fails first.
-
85% 失败
pip build isolation creates a fresh env for the build, so the host setuptools is not visible.
-
70% 失败
If the project still needs setup.py for dynamic metadata, removing it breaks the build entirely.