mysqlclient 报错libstdc++.so.6: cannot allocate memory in static TLS block 修复

最近工作中要用到dask分布式集群, 这要求每一个节点的环境和包的版本都是一致的,在linux上的一个节点就出现了如下错误

Traceback (most recent call last):
  File "/home/voke/MF_mom_spd.py", line 32, in <module>
    from slc_data.db.database_engine import OnlineMySQLConn
  File "/root/miniconda3/envs/daskservice/lib/python3.9/site-packages/slc_data/db/database_engine.py", line 4, in <module>
    import MySQLdb
  File "/root/miniconda3/envs/daskservice/lib/python3.9/site-packages/MySQLdb/__init__.py", line 17, in <module>
    from . import _mysql
ImportError: /root/miniconda3/envs/daskservice/bin/../lib/libstdc++.so.6: cannot allocate memory in static TLS block

首先查询是否已经安装了 libstdc++.so.6

locate libstdc++.so.6
/opt/nvidia/nsight-compute/2023.2.0/host/linux-desktop-glibc_2_11_3-x64/libstdc++.so.6
/opt/nvidia/nsight-systems/2023.2.3/host-linux-x64/libstdc++.so.6
/root/miniconda3/envs/daskservice/lib/libstdc++.so.6
/root/miniconda3/envs/daskservice/lib/libstdc++.so.6.0.29
/root/miniconda3/envs/stock_pytorch/lib/libstdc++.so.6
/root/miniconda3/envs/stock_pytorch/lib/libstdc++.so.6.0.29

其次检测是否安装了libmysqlclient-dev(linux下mysqlclient的库文件)

locate libmysqlclient-dev
/usr/share/doc/libmysqlclient-dev
/usr/share/doc/libmysqlclient-dev/copyright
/usr/share/doc/libmysqlclient-dev/examples
/usr/share/doc/libmysqlclient-dev/examples/udf_example.cc.gz
/var/lib/dpkg/info/libmysqlclient-dev.list
/var/lib/dpkg/info/libmysqlclient-dev.md5sums

如果没有安装,安装一下

apt install libmysqlclient-dev

通过上面的排查发现我的包都已正常安装,一开始是以为windows和linux节点的包不一致的问题, 后面只在Linux上直接运行程序依旧报错,在goole一通后,在github上找到了解决办法ibstdc++.so.6: cannot allocate memory in static TLS block

大致的意思是

It seems some dependency started to request more than 2Kb allocated by default for the TLS storage.
The workaround is to change of shared libraries loading by adding

export LD_PRELOAD=/lib/x86_64-linux-gnu/libstdc++.so.6:$LD_PRELOAD

执行上面的命令指定运行的包的位置即可,该问题只在mysql8.0执行多线程连接的时容易出现

你可能感兴趣的:(Python,mysqlclient,python)