本文介绍了导入错误:没有名为flaskext.sqlalchemy 的模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用来自 Flask 站点的 使用 SteamID 登录 片段.但是,当我尝试运行它时,我收到 ImportError: No module named flaskext.sqlalchemy,并且 PyCharm 说 Uresolved reference "flaskext"Uresolved reference "OpenID".我重新安装了 Flask-OpenID 和 Flask-SQLAlchemy 以确保它们在那里.为什么我会收到这个错误,我该如何解决?

解决方案

那个片段真的很老了.flaskext 不再(或至少非常不推荐使用).直接引用包,而不是通过 flaskextflask.ext.

from flask_sqlalchemy import SQLAlchemy

Flask-SQLAlchemy(和大多数其他扩展)不再在 flaskext 命名空间中注册,并且 flask.ext 已弃用 然后 在 1.0 中移除.现在引用扩展的唯一正确方法是直接导入它们.

如果您仍然遇到导入错误,则说明您没有在运行的 Python 环境中安装软件包.确保您使用的是 virtualenv.>

I am trying to use the Sign in with SteamID snippet from the Flask site. However, I get ImportError: No module named flaskext.sqlalchemy when I try to run it, and PyCharm says Uresolved reference "flaskext" and Uresolved reference "OpenID". I re-installed Flask-OpenID and Flask-SQLAlchemy to make sure they were there. Why am I getting this error and how do I fix it?

解决方案

That snippet is really old. flaskext is no more (or at least very deprecated). Refer to packages directly rather than through flaskext or flask.ext.

from flask_sqlalchemy import SQLAlchemy

Flask-SQLAlchemy (and most other extensions) no longer register in the flaskext namespace, and flask.ext was deprecated then removed in 1.0. The only correct way to refer to extensions now is by directly importing them.

If you're still getting an import error, then you didn't install the package in the same Python environment you're running. Make sure you're using a virtualenv.

这篇关于导入错误:没有名为flaskext.sqlalchemy 的模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-10 13:18