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

问题描述

我正尝试使用Flask站点的片段。但是,我得到 ImportError:当我尝试运行它时没有名为flaskext.sqlalchemy 的模块,PyCharm说 Uresolved referenceflaskext Uresolved引用OpenID。我重新安装了Flask-OpenID和Flask-SQLAlchemy以确保它们在那里。为什么我得到这个错误,我该如何解决这个问题?

flaskext 没有更多(或至少非常不赞成)。直接引用包,而不是通过 flaskext flask.ext

  from flask_sqlalchemy import SQLAlchemy 

Flask-SQLAlchemy和大多数其他扩展)不再注册在 flaskext 命名空间中,并且。现在引用扩展的唯一正确方法就是直接导入它们。

如果仍然出现导入错误,那么您没有在您正在运行的Python环境相同。确保您使用的是。 p>

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 is deprecated. 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.

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

09-26 22:38