(flask-projs) [root@test-xxxx-01-vm]# python app.py Traceback (most recent call last): File "/data/colinspace/temp/flask-demo/demoproj/app.py", line 5, in <module> from flask_script import Manager File "/data/colinspace/.pyenv/versions/flask-projs/lib/python3.9/site-packages/flask_script/__init__.py", line 15, in <module> from flask._compat import text_type ModuleNotFoundError: No module named 'flask._compat'
刚开始没有仔细看错误信息,惯性的去网上查找解决方案,大多都说是高版本存在问题,需要降配处理。
先说结果: 其实不用降配处理,因为从错误中就可以发现问题所在
检查了下本地安装的版本
1 2
Flask 2.2.2 Flask-Script 2.0.6
尝试降配到 1.1.4 、1.1.3 和 1.1.2 然后运行,又出现了很多其他类似的问题,比如
1
ImportError: cannot import name 'json' from 'itsdangerous'
或者
1
ImportError: cannot import name 'escape' from 'jinja2'
from flask import Flask from flask_script import Manager
app = Flask(__name__) manager = Manager(app)
if __name__ == '__main__': # 注意这里被 manager.run()接管, 而不是app.run() manager.run()
这个时候执行 python app.py 不会直接启动一个 http server,而是输出如下:
1 2 3 4 5 6 7 8 9
usage: app.py [-?] {shell,runserver} ...
positional arguments: {shell,runserver} shell Runs a Python shell inside Flask application context. runserver Runs the Flask development server i.e. app.run()
optional arguments: -?, --help show this help message and exit
optional arguments: -?, --help show this help message and exit -h HOST, --host HOST -p PORT, --port PORT --threaded --processes PROCESSES --passthrough-errors -d, --debug enable the Werkzeug debugger (DO NOT use in production code) -D, --no-debug disable the Werkzeug debugger -r, --reload monitor Python files for changes (not 100% safe for production use) -R, --no-reload do not monitor Python files for changes --ssl-crt SSL_CRT Path to ssl certificate --ssl-key SSL_KEY Path to ssl key