简体   繁体   English

AttributeError: 模块 'sqlalchemy.orm' 没有属性 'DeclarativeMeta'

[英]AttributeError: module 'sqlalchemy.orm' has no attribute 'DeclarativeMeta'

Getting the below error while running a flask application:运行 flask 应用程序时出现以下错误:

ubuntu@ip-10-50-50-190:~/RHS_US/application$ python3 run.py                                                                                                                                                 
Traceback (most recent call last):
File "run.py", line 1, in <module>
from portal import create_app
File "/home/ubuntu/RHS_US/application/portal/__init__.py", line 7, in <module>
from flask_sqlalchemy import SQLAlchemy
File "/home/ubuntu/RHS_US/application/rhs_us_venv/lib/python3.7/site- 
packages/flask_sqlalchemy/__init__.py", line 5, in <module>
from .extension import SQLAlchemy
File "/home/ubuntu/RHS_US/application/rhs_us_venv/lib/python3.7/site- 
packages/flask_sqlalchemy/extension.py", line 17, in <module>
from .model import _QueryProperty
File "/home/ubuntu/RHS_US/application/rhs_us_venv/lib/python3.7/site- 
packages/flask_sqlalchemy/model.py", line 210, in <module>
class DefaultMeta(BindMetaMixin, NameMetaMixin, sa.orm.DeclarativeMeta):

AttributeError: module 'sqlalchemy.orm' has no attribute 'DeclarativeMeta'

I have also checked model.py under site packages and it does contain我还检查了站点包下的 model.py,它确实包含

class DefaultMeta(BindMetaMixin, NameMetaMixin, sa.orm.DeclarativeMeta): class DefaultMeta(BindMetaMixin,NameMetaMixin,sa.orm.DeclarativeMeta):

Do pip freeze to see packages versions.执行pip freeze查看软件包版本。 Maybe you have incompatible sqlalchemy and flask-sqlalchemy packages.也许你有不兼容的 sqlalchemy 和 flask-sqlalchemy 包。 I recently ocasionaly updated my sqlalchemy package from 1.23.X to 1.4.X and one of projects, dependent on 1.23.X failed to work correctly until I noticed it and degraded sqlalchemy. But because of this I got the same exception.我最近偶尔将我的 sqlalchemy package 从 1.23.X 更新到 1.4.X,其中一个依赖 1.23.X 的项目无法正常工作,直到我注意到它并降级了 sqlalchemy。但正因为如此,我遇到了同样的异常。 I tried to install older versions of flask-sqlalchemy:我尝试安装旧版本的 flask-sqlalchemy:

pip install Flask-SQLAlchemy==2.4.4

But it thrown the next exception:但它引发了下一个异常:

'_FakeStack' object has no attribute ' ident_func ' '_FakeStack' object 没有属性 ' ident_func '

So I tried to install 2.5.0:所以我尝试安装 2.5.0:

pip install Flask-SQLAlchemy==2.5.0

After this my flask project started without issues.在此之后,我的 flask 项目顺利启动。 Then I returned 2.5.1 and it also started without issues.然后我返回 2.5.1,它也没有问题地启动。

So in my case the cause of the issue was degrading sqlalchemy package, which is gone after reinstalling Flask-SQLAlchemy package所以在我的例子中,问题的原因是降级 sqlalchemy package,重新安装 Flask-SQLAlchemy package 后就消失了

But I'm currently on python 3.11 windows. In your case the cause of the issue could differ.但我目前正在使用 python 3.11 windows。在您的情况下,问题的原因可能有所不同。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从 flask_sqlalchemy 导入 SQLAlchemy 时出错:AttributeError: module 'sqlalchemy.orm' has no attribute 'DeclarativeMeta' - Error importing SQLAlchemy from flask_sqlalchemy: AttributeError: module 'sqlalchemy.orm' has no attribute 'DeclarativeMeta' SQLAlchemy AttributeError: &#39;module&#39; 对象没有属性 &#39;PandasSQLAlchemy&#39; - SQLAlchemy AttributeError: 'module' object has no attribute 'PandasSQLAlchemy' AttributeError: 模块 &#39;sqlalchemy&#39; 没有属性 &#39;NullType&#39; - AttributeError: module 'sqlalchemy' has no attribute 'NullType' 烧瓶SQLAlchemy的。 AttributeError:模块“ &lt;…&gt; .db”没有属性“ Model” - Flask-SQLAlchemy. AttributeError: module '<…>.db' has no attribute 'Model' AttributeError: 模块 &#39;sqlalchemy.util&#39; 没有属性 &#39;deprecated_pa​​rams&#39; - AttributeError: module 'sqlalchemy.util' has no attribute 'deprecated_params' AttributeError:模块“sqlalchemy.dialects”没有属性“postgresql” - AttributeError: module 'sqlalchemy.dialects' has no attribute 'postgresql' AttributeError:模块“时间”在 SQLAlchemy python 3.8.2 中没有属性“时钟” - AttributeError: module 'time' has no attribute 'clock' In SQLAlchemy python 3.8.2 AttributeError:模块“sqlalchemy”在 github 操作中没有属性“__all__” - AttributeError: module 'sqlalchemy' has no attribute '__all__' in github actions AttributeError: 模块 ' ' 没有属性 ' ' - AttributeError: module ' ' has no attribute ' ' AttributeError:模块没有属性 - AttributeError: module has no attribute
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM