[Solved] SQLAlchemy Error: ImportError: cannot import name ‘TYPE_CHECKING’

Error content:

[2021-04-14 20:43:32 +0800] [8560] [ERROR] Exception in worker process
Traceback (most recent call last):
  File "/data/app/abadmin/current/venv/lib/python3.5/site-packages/gunicorn/arbiter.py", line 583, in spawn_worker
    worker.init_process()
  File "/data/app/abadmin/current/venv/lib/python3.5/site-packages/gunicorn/workers/ggevent.py", line 203, in init_process
    super(GeventWorker, self).init_process()
  File "/data/app/abadmin/current/venv/lib/python3.5/site-packages/gunicorn/workers/base.py", line 129, in init_process
    self.load_wsgi()
  File "/data/app/abadmin/current/venv/lib/python3.5/site-packages/gunicorn/workers/base.py", line 138, in load_wsgi
    self.wsgi = self.app.wsgi()
  File "/data/app/abadmin/current/venv/lib/python3.5/site-packages/gunicorn/app/base.py", line 67, in wsgi
    self.callable = self.load()
  File "/data/app/abadmin/current/venv/lib/python3.5/site-packages/gunicorn/app/wsgiapp.py", line 52, in load
    return self.load_wsgiapp()
  File "/data/app/abadmin/current/venv/lib/python3.5/site-packages/gunicorn/app/wsgiapp.py", line 41, in load_wsgiapp
    return util.import_app(self.app_uri)
  File "/data/app/abadmin/current/venv/lib/python3.5/site-packages/gunicorn/util.py", line 350, in import_app
    __import__(module)
  File "/data/app/abadmin/releases/feat-cag-related-users-tapd-1158596607001160647-9bec0f48/abadmin.py", line 5, in <module>
    from app import app
  File "/data/app/abadmin/releases/feat-cag-related-users-tapd-1158596607001160647-9bec0f48/app/__init__.py", line 13, in <module>
    from flask_sqlalchemy import SQLAlchemy
  File "/data/app/abadmin/current/venv/lib/python3.5/site-packages/flask_sqlalchemy/__init__.py", line 22, in <module>
    import sqlalchemy
  File "/data/app/abadmin/current/venv/lib/python3.5/site-packages/sqlalchemy/__init__.py", line 8, in <module>
    from . import util as _util  # noqa
  File "/data/app/abadmin/current/venv/lib/python3.5/site-packages/sqlalchemy/util/__init__.py", line 14, in <module>
    from ._collections import coerce_generator_arg  # noqa
  File "/data/app/abadmin/current/venv/lib/python3.5/site-packages/sqlalchemy/util/_collections.py", line 16, in <module>
    from .compat import binary_types
  File "/data/app/abadmin/current/venv/lib/python3.5/site-packages/sqlalchemy/util/compat.py", line 189, in <module>
    from typing import TYPE_CHECKING
ImportError: cannot import name 'TYPE_CHECKING'
[2021-04-14 20:43:32 +0800] [8560] [INFO] Worker exiting (pid: 8560)

reason

  1. The python version used is 3.5
  2. Flask-SQLAlchemy 2.3.2 will install SQLAlchemy 1.3.22
  3. This version of SQLAlchemy 1.3.22 has a bug: https://github.com/sqlalchemy/sqlalchemy/issues/6213 , so the above error is reported

solve

Do not use the SQLAlchemy version installed by Flask-SQLAlchemy, specify the SQLAlchemy version as 1.3.22, and write in the requirements.txt file:SQLAlchemy==1.3.22

Similar Posts:

Leave a Reply

Your email address will not be published. Required fields are marked *