👨🏻💻 热爱摄影的程序员
👨🏻🎨 喜欢编码的设计师
🧕🏻 擅长设计的剪辑师
🧑🏻🏫 一位高冷无情的全栈工程师
欢迎分享 / 收藏 / 赞 / 在看!
【问题】
在使用 Flask 框架进行开发时,出现如下错误:
FLASK_APP = app.py
FLASK_ENV = development
FLASK_DEBUG = 0
In folder /Users/hayden/Desktop/FemaleHelth
/Users/hayden/Envs/flaskEnv/bin/python -m flask run
Traceback (most recent call last):
File "/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/runpy.py", line 188, in _run_module_as_main
mod_name, mod_spec, code = _get_module_details(mod_name, _Error)
File "/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/runpy.py", line 147, in _get_module_details
return _get_module_details(pkg_main_name, error)
File "/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/runpy.py", line 111, in _get_module_details
__import__(pkg_name)
File "/Users/hayden/Envs/flaskEnv/lib/python3.9/site-packages/flask/__init__.py", line 5, in <module>
from .app import Flask as Flask
File "/Users/hayden/Envs/flaskEnv/lib/python3.9/site-packages/flask/app.py", line 30, in <module>
from werkzeug.urls import url_quote
ImportError: cannot import name 'url_quote' from 'werkzeug.urls' (/Users/hayden/Envs/flaskEnv/lib/python3.9/site-packages/werkzeug/urls.py)
Process finished with exit code 1
【解决】
这个错误通常是因为版本不兼容或者依赖关系出了问题。看起来是 Werkzeug 库的导入问题,这可能是由于不匹配的库版本造成的。
尝试更新 Werkzeug 库到最新版本,可以通过以下命令来升级 Werkzeug:
pip install --upgrade Werkzeug
另外,确保你的 Flask 也是最新版本,可以运行以下命令来升级到最新版:
pip install --upgrade Flask