导入 flask.ext 引发 ModuleNotFoundError [英] Importing flask.ext raises ModuleNotFoundError

查看:19
本文介绍了导入 flask.ext 引发 ModuleNotFoundError的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试使用 Flask 扩展时,我的应用程序在诸如 from flask.ext.sqlalchemy import SQLAlchemyfrom flask.exthook 之类的行上引发 ModuleNotFound 错误导入 ExtDeprecationWarning.我已经安装了 Flask 和扩展程序.为什么会出现此错误?

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.extflask.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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆