我在网上搜索过,但没有找到任何可以解决我的问题的内容。我正在使用 Python 在 Flask 中编写一个 Web 应用程序,但将数据传输到新计算机并重新创建虚拟环境后,我无法再使用 Flask 的内置开发 Web 服务器。我在下面得到了回溯。我无法判断问题是否出在 SQL 或 Flask 模块中,但我尝试重新安装并从源代码编译它们,但无济于事。即使不在虚拟环境中,应用程序也会引发相同的错误。
127.0.0.1 - - [07/Aug/2020 14:29:49] "GET / HTTP/1.1" 500 -
Traceback (most recent call last):
File "/home/jhonig/ttx/venv/lib/python3.8/site-packages/sqlalchemy/util/_collections.py", line 1020, in __call__
return self.registry[key]
KeyError: 139700690765568
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/jhonig/ttx/venv/lib/python3.8/site-packages/flask/app.py", line 2463, in __call__
return self.wsgi_app(environ, start_response)
File "/home/jhonig/ttx/venv/lib/python3.8/site-packages/flask/app.py", line 2449, in wsgi_app
response = self.handle_exception(e)
File "/home/jhonig/ttx/venv/lib/python3.8/site-packages/flask/app.py", line 1866, in handle_exception
reraise(exc_type, exc_value, tb)
File "/home/jhonig/ttx/venv/lib/python3.8/site-packages/flask/_compat.py", line 39, in reraise
raise value
File "/home/jhonig/ttx/venv/lib/python3.8/site-packages/flask/app.py", line 2446, in wsgi_app
response = self.full_dispatch_request()
File "/home/jhonig/ttx/venv/lib/python3.8/site-packages/flask/app.py", line 1952, in full_dispatch_request
return self.finalize_request(rv)
File "/home/jhonig/ttx/venv/lib/python3.8/site-packages/flask/app.py", line 1969, in finalize_request
response = self.process_response(response)
File "/home/jhonig/ttx/venv/lib/python3.8/site-packages/flask/app.py", line 2268, in process_response
self.session_interface.save_session(self, ctx.session, response)
File "/home/jhonig/ttx/venv/lib/python3.8/site-packages/flask_session/sessions.py", line 534, in save_session
saved_session = self.sql_session_model.query.filter_by(
File "/home/jhonig/ttx/venv/lib/python3.8/site-packages/flask_sqlalchemy/__init__.py", line 519, in __get__
return type.query_class(mapper, session=self.sa.session())
File "/home/jhonig/ttx/venv/lib/python3.8/site-packages/sqlalchemy/orm/scoping.py", line 78, in __call__
return self.registry()
File "/home/jhonig/ttx/venv/lib/python3.8/site-packages/sqlalchemy/util/_collections.py", line 1022, in __call__
return self.registry.setdefault(key, self.createfunc())
File "/home/jhonig/ttx/venv/lib/python3.8/site-packages/sqlalchemy/orm/session.py", line 3286, in __call__
return self.class_(**local_kw)
File "/home/jhonig/ttx/venv/lib/python3.8/site-packages/flask_sqlalchemy/__init__.py", line 138, in __init__
bind = options.pop('bind', None) or db.engine
File "/home/jhonig/ttx/venv/lib/python3.8/site-packages/flask_sqlalchemy/__init__.py", line 937, in engine
return self.get_engine()
File "/home/jhonig/ttx/venv/lib/python3.8/site-packages/flask_sqlalchemy/__init__.py", line 956, in get_engine
return connector.get_engine()
File "/home/jhonig/ttx/venv/lib/python3.8/site-packages/flask_sqlalchemy/__init__.py", line 561, in get_engine
self._engine = rv = self._sa.create_engine(sa_url, options)
File "/home/jhonig/ttx/venv/lib/python3.8/site-packages/flask_sqlalchemy/__init__.py", line 966, in create_engine
return sqlalchemy.create_engine(sa_url, **engine_opts)
File "/home/jhonig/ttx/venv/lib/python3.8/site-packages/sqlalchemy/engine/__init__.py", line 500, in create_engine
return strategy.create(*args, **kwargs)
File "/home/jhonig/ttx/venv/lib/python3.8/site-packages/sqlalchemy/engine/strategies.py", line 87, in create
dbapi = dialect_cls.dbapi(**dbapi_args)
File "/home/jhonig/ttx/venv/lib/python3.8/site-packages/sqlalchemy/dialects/mysql/mysqldb.py", line 118, in dbapi
return __import__("MySQLdb")
File "/home/jhonig/ttx/venv/lib/python3.8/site-packages/MySQLdb/__init__.py", line 18, in <module>
from . import _mysql
ImportError: /lib/x86_64-linux-gnu/libstdc++.so.6: cannot allocate memory in static TLS block
对于任何可能遇到此问题的人,
libmysqlclient21
软件包存在问题,已在 8.0.21
版本中修复:
错误:https://bugs.launchpad.net/ubuntu/+source/opencv/+bug/1890170
修复:https://bugs.launchpad.net/ubuntu/+source/mysql-8.0/+bug/1889851
使用
sudo apt upgrade
升级我的系统似乎解决了这个问题,尽管我不知道如何解决。看来一些 MySQL 软件包已更新,所以也许这是一个错误?
为了方便后代,这里是已升级的软件包列表:
The following packages will be upgraded:
libmysqlclient-dev libmysqlclient21 libmysqlclient21:i386 linux-generic
linux-headers-5.4.0-7634 linux-headers-5.4.0-7634-generic linux-headers-generic
linux-image-5.4.0-7634-generic linux-image-generic linux-libc-dev
linux-modules-5.4.0-7634-generic linux-modules-extra-5.4.0-7634-generic
linux-system76 openjdk-8-jre-headless pop-shell
15 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
export LD_PRELOAD=/usr/lib64/libstdc++.so.6
可以帮助使用 pydoris、sqlalchemy 的人更改 libstdc++.so 位置以适合您的机器。
Linux:红帽8.7
Python 3.6.8
我正在使用 pysqlchemy 编写 python 脚本。
yum install mysql-devel gcc-c++
pip3 install pydoris
...
from sqlalchemy import create_engine
from sqlalchemy.schema import Table, MetaData
...
Traceback (most recent call last):
File "/usr/local/lib64/python3.6/site-packages/MySQLdb/__init__.py", line 18, in <module>
from . import _mysql
ImportError: /lib64/libstdc++.so.6: cannot allocate memory in static TLS block
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/data_b/data/azkaban/jobFile/10292/1736242219037/mysql_doris.py", line 68, in <module>
insert_doris(parsed_data)
File "/data_b/data/azkaban/jobFile/10292/1736242219037/mysql_doris.py", line 55, in insert_doris
engine = create_engine("doris://{username}:{password}@{host}/{schema}")
File "<string>", line 2, in create_engine
File "/usr/local/lib64/python3.6/site-packages/sqlalchemy/util/deprecations.py", line 375, in warned
return fn(*args, **kwargs)
File "/usr/local/lib64/python3.6/site-packages/sqlalchemy/engine/create.py", line 544, in create_engine
dbapi = dialect_cls.dbapi(**dbapi_args)
File "/usr/local/lib64/python3.6/site-packages/sqlalchemy/dialects/mysql/mysqldb.py", line 150, in dbapi
return __import__("MySQLdb")
File "/usr/local/lib64/python3.6/site-packages/MySQLdb/__init__.py", line 24, in <module>
version_info, _mysql.version_info, _mysql.__file__
NameError: name '_mysql' is not defined