SQLAlchemy 报错:ImportError: cannot import name 'TYPE_CHECKING',安装的版本有bug,换版本解决
报错内容:
[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)
原因
- 使用的python版本为3.5
- Flask-SQLAlchemy 2.3.2会安装SQLAlchemy 1.3.22
- SQLAlchemy的这个版本1.3.22,有bug:https://github.com/sqlalchemy/sqlalchemy/issues/6213 ,所以报上面错误
解决
不使用 Flask-SQLAlchemy 安装的SQLAlchemy版本,指定SQLAlchemy版本为1.3.22,requirements.txt文件中写入:SQLAlchemy==1.3.22
资料
资料 | 网址 |
---|---|
bug issues | https://github.com/sqlalchemy/sqlalchemy/issues/6213 |