|
ModuleNotFoundError: No module named ‘flask._compat
使用flask_script管理flask启动
注意:
- 最后两个错有解决没有略过至于报错顺序
- 在解决完flask版本 Jinja2 有可能会报错 看自己的版本 最后一个Jinja2错误是复现出来的
代码:- from flask import Flask
- import config
- from flask_script import Manager
- app=Flask(__name__)
- #app.config.from_object(config.MyConfig)
- manager = Manager(app)
- if __name__ == '__main__':
- manager.run()
复制代码 报错信息
- Traceback (most recent call last): File "<frozen importlib._bootstrap>", line 991, in _find_and_load File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 671, in _load_unlocked File "<frozen importlib._bootstrap_external>", line 843, in exec_module File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed File "/Users/tly/opt/anaconda3/envs/FlaskProject/lib/python3.8/site-packages/flask_script/__init__.py", line 15, in <module> from flask._compat import text_typeModuleNotFoundError: No module named 'flask._compat'
复制代码 查看安装的包
发现安装的flask的版本过高没有 直接拉取的话就是最新版的
版本降低即可解决
- pip3 install flask==1.1.4
复制代码 版本更新完
接着又报错
- Traceback (most recent call last): File "test3.py", line 1, in <module> from flask import Flask File "/Users/tly/opt/anaconda3/envs/FlaskProject/lib/python3.8/site-packages/flask/__init__.py", line 14, in <module> from jinja2 import escape File "/Users/tly/opt/anaconda3/envs/FlaskProject/lib/python3.8/site-packages/jinja2/__init__.py", line 12, in <module> from .environment import Environment File "/Users/tly/opt/anaconda3/envs/FlaskProject/lib/python3.8/site-packages/jinja2/environment.py", line 25, in <module> from .defaults import BLOCK_END_STRING File "/Users/tly/opt/anaconda3/envs/FlaskProject/lib/python3.8/site-packages/jinja2/defaults.py", line 3, in <module> from .filters import FILTERS as DEFAULT_FILTERS # noqa: F401 File "/Users/tly/opt/anaconda3/envs/FlaskProject/lib/python3.8/site-packages/jinja2/filters.py", line 13, in <module> from markupsafe import soft_unicodeImportError: cannot import name 'soft_unicode' from 'markupsafe'
复制代码 查看markupsafe版本发现是2.1.1
markupsafe版本降低
- python -m pip install markupsafe==2.0.1
复制代码 来继续报错- Traceback (most recent call last): File "test3.py", line 1, in <module> from flask import Flask File "/Users/tly/opt/anaconda3/envs/FlaskProject/lib/python3.8/site-packages/flask/__init__.py", line 14, in <module> from jinja2 import escapeImportError: cannot import name 'escape' from 'jinja2' (/Users/tly/opt/anaconda3/envs/FlaskProject/lib/python3.8/site-packages/jinja2/__init__.py)
复制代码 继续降版本
- pip install Jinja2==3.0.0
复制代码
到此为止输入命令- python test3.py runserver
复制代码 项目启动起来
总结
以上为个人经验,希望能给大家一个参考,也希望大家多多支持脚本之家。
来源:https://www.jb51.net/python/3220511eg.htm
免责声明:由于采集信息均来自互联网,如果侵犯了您的权益,请联系我们【E-Mail:cb@itdo.tech】 我们会及时删除侵权内容,谢谢合作! |
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有账号?立即注册
x
|