使用 flask_script 管理flask启动 注意:最后两个错有解决没有略过至于报错顺序 , 在解决完flask版本 Jinja2 有可能会报错 看自己的版本 最后一个Jinja2错误是复现出来的
代码
from flask import Flask
import config
from flask_script import Manager
app=Flask(__name__)
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_type
ModuleNotFoundError: No module named 'flask._compat'
查看安装的包
pip freeze
发现安装的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
File "/Users/tly/opt/anaconda3/envs/FlaskProject/lib/python3.8/site-packages/jinja2/filters.py", line 13, in <module>
from markupsafe import soft_unicode
ImportError: 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 escape
ImportError: 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 项目启动起来
|