导入 flask.ext 引发 ModuleNotFoundError [英] Importing flask.ext raises ModuleNotFoundError
问题描述
当我尝试使用 Flask 扩展时,我的应用程序在诸如 from flask.ext.sqlalchemy import SQLAlchemy
或 from flask.exthook 之类的行上引发
.我已经安装了 Flask 和扩展程序.为什么会出现此错误?ModuleNotFound
错误导入 ExtDeprecationWarning
When I try to use Flask extensions, my application is raising ModuleNotFound
errors on lines like from flask.ext.sqlalchemy import SQLAlchemy
or from flask.exthook import ExtDeprecationWarning
. I have Flask and the extension installed. Why do I get this error?
推荐答案
您的代码或您正在使用的代码中的某些内容正在尝试导入 flask.ext
或 flask.exthook
,在 Flask 1.0 中不再存在.它们在被明显弃用至少一年后被完全删除,并在此之前隐式弃用了很多年.任何仍然依赖它的东西都必须升级.
Something in your code, or in code you're using, is trying to import flask.ext
or flask.exthook
, which no longer exists in Flask 1.0. They were completely removed after being visibly deprecated for at least a year, and implicitly deprecated for many years before that. Anything that still depends on it must be upgraded.
任何使用 from flask.ext import ...
都应替换为直接导入扩展.例如 flask.ext.sqlalchemy
变成 flask_sqlalchemy
.
Any use of from flask.ext import ...
should be replaced with a direct import of the extension. For example flask.ext.sqlalchemy
becomes flask_sqlalchemy
.
导入 from flask.exthook import ExtDeprecationWarning
的唯一原因是消除之前的弃用警告.既然已经不存在了,就不会有静默警告,那段代码就可以删除了.
The only reason to import from flask.exthook import ExtDeprecationWarning
is to silence the previous deprecation warnings. Since it no longer exists, there is no warning to silence, and that code can be removed.
这篇关于导入 flask.ext 引发 ModuleNotFoundError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!