ImportError: cannot import name '_ColumnEntity' from 'sqlalchemy.orm.query'
Asked Answered
F

5

22

After installing apache-superset using pip in virtual environment, I run:

superset upgrade db   

I run into the following error:

ImportError: cannot import name '_ColumnEntity' from 'sqlalchemy.orm.query' (/Users/ahmedawny/supersetenv/lib/python3.7/site-packages/sqlalchemy/orm/query.py)

Any advice would be appreciated.

Fayfayal answered 15/3, 2021 at 20:8 Comment(6)
im on the same boat, for some reason theres not a single question like this, or google cant identify characters ldkSelfaddressed
github.com/kvesteri/sqlalchemy-utils/issues/474Marleah
@Marleah what file do I change that sqlalchemy import?Fayfayal
How do I know? You haven't shown the full traceback.Marleah
I filed a bug report github.com/sqlalchemy/sqlalchemy/issues/6226Systemic
see also github.com/kvesteri/sqlalchemy-utils/issues/505Systemic
E
45

The core reason for this is that sqlalchemy 1.4 shipped, so it is now the default that pip installs. There were many interface changes and a new query interface added.

So upgrading to 1.4 breaks stuff that depends on the sqlalchemy 1.3 API internals. In your requirements.txt file-- pin the project version to the 1.3.x series until the rest of your stuff catches up. For example, as of this date sqlalchemy-utils is still dependent on sqlalchemy 1.3x.

requirements.txt:

sqlalchemy < 1.4.0

Then use:

pip -r requirements.txt

to "downgrade" to the pinned version.

Expostulatory answered 16/3, 2021 at 1:52 Comment(2)
Who does breaking changes from 1.3.x to 1.4.0? (sigh)Monotony
latest Flask-Migrate requires sqlalchemy 1.4.Standford
R
5

If you don't want to modify the requirements file, as recommended in @InsertSpywareTrackingHere's answer, you can manually pip install an older version instead:

pip install sqlalchemy==1.3.24
Reading answered 1/12, 2021 at 1:17 Comment(3)
Isn't this just a less flexible version of the top-voted answer? Please read How to Answer.Alagez
This does not provide an answer to the question. Once you have sufficient reputation you will be able to comment on any post; instead, provide answers that don't require clarification from the asker. - From ReviewCento
While this is equivalent to the top-voted answer, once you know what you're doing, I think this answer has value for the beginner, and I would encourage reviewers not to delete it.Unrestraint
M
2

Go to sqlalchemy_utils.functions file and change :

  • from sqlalchemy.orm.query import _ColumnEntity (comment this one, or delete it)
  • from sqlalchemy.orm.context import _ColumnEntity (include)

in consequence of this, i belive it should change some stuff along the code...

Metabolism answered 17/3, 2021 at 21:54 Comment(0)
V
2

you can temporarily fix this by changing the imports in sqlalchemy_utils\functions\orm.py:

from sqlalchemy.orm.query import _ColumnEntity

to

from sqlalchemy.orm.context import _ColumnEntity
Virgievirgil answered 13/4, 2021 at 5:1 Comment(1)
how can i go to sqlalchemy_utils\functions\orm.py it is installed on online server, pythonanywhere.comProphetic
B
1

@InsertSpywareTrackingHere answer is correct, Just want to add that a new release for Flask-AppBuilder was made that pins SQLAlchemy bellow 1.4.0. So installing apache-superset using pip install apache-superset should work now.

Bharat answered 17/3, 2021 at 21:36 Comment(1)
I just pip installed apache-superset fresh. it complained with "flask-appbuilder 3.2.2 requires SQLAlchemy<1.4.0, but you'll have sqlalchemy 1.4.7 which is incompatible." but finished. I still needed to manually pip install sqlalchemy==1.3.24 after. perhaps the dependency ordering in the setup.py is not right? I am not an expert.Preston

© 2022 - 2024 — McMap. All rights reserved.