python
module_error
ai_generated
true
ImportError: cannot import name 'bp' from partially initialized module 'app.routes' (most likely due to a circular import)
ID: python/flask-circular-import-blueprint
80%Fix Rate
86%Confidence
0Evidence
2024-07-24First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 2.x | active | — | — | — |
| 3.x | active | — | — | — |
Root Cause
Two modules import each other, often app -> routes -> app for `app` object or blueprint registration.
generic中文
两个模块相互导入,通常是app -> routes -> app以获取app对象或注册蓝图。
Workarounds
-
93% success
def create_app():\n app = Flask(__name__)\n from .routes import bp\n app.register_blueprint(bp)\n return app
-
88% success
def register():\n from .routes import bp\n app.register_blueprint(bp)
Dead Ends
Common approaches that don't work:
-
65% fail
Still executed at import time; cycle remains.
-
90% fail
Cycle is structural, not naming.