python
module_error
ai_generated
true
ImportError: cannot import name 'setup' from 'setuptools' (/path/to/setuptools/__init__.py)
ID: python/setuptools-cannot-import-setup-from-setuptools
80%Fix Rate
86%Confidence
0Evidence
2024-07-29First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 3.8 | active | — | — | — |
| 3.9 | active | — | — | — |
| 3.10 | active | — | — | — |
| 3.11 | active | — | — | — |
| 3.12 | active | — | — | — |
Root Cause
A local file named setuptools.py shadows the package, or the installed setuptools is corrupted/incompletely uninstalled, leaving a partial __init__.py without setup.
generic中文
本地存在名为 setuptools.py 的文件遮蔽了包,或已安装的 setuptools 损坏/卸载不完整,留下缺少 setup 的部分 __init__.py。
Workarounds
-
90% success
find . -maxdepth 3 -name 'setuptools.py' -print # rename/delete it mv ./setuptools.py ./setuptools.py.bak
-
85% success
python -m venv .venv && . .venv/bin/activate pip install --upgrade --force-reinstall setuptools
-
80% success
python -c "import setuptools, inspect; print(setuptools.__file__); print(hasattr(setuptools, 'setup'))"
Dead Ends
Common approaches that don't work:
-
70% fail
If a local setuptools.py shadows the package, upgrade doesn't help.
-
85% fail
It's a build-time dependency, not a runtime one.
-
90% fail
Destroys the environment; you'll need to rebuild it.