在写flask项目时候
遇到错误ModuleNotFoundError: No module named ‘flask._compat’
代码如下
from flask_script import Manager, Shell
manager = Manager(app)
# ......
if __name__ == '__main__':
manager.run()
查了一下这问题的原因是因为版本问题,我的flask版本是2.x版本的,网上很多答案都说需要把flask回退到1.x版本。
对于懒得折腾的我来说实在是太淦了把
一度想要放弃时候看到SO上面的解决方法,亲测可行,然后把解决过程贴过来。
先来看这个报错
Traceback (most recent call last):
File "hello.py", line 10, in <module>
from flask_script import Manager, Shell
File "D:\software\anaconda\lib\site-packages\flask_script\__init__.py", line 15, in <module>
from flask._compat import text_type
ModuleNotFoundError: No module named 'flask._compat
也就是在导入flask_script的时候就有问题了
进去到flask_script 的__init__中, 第15行的问题
把
from flask._compat import text_type
变成:
from flask_script._compat import text_type
就可以了
大功告成,可以进入shell了: