同一个 python 包,几乎同样的环境,本地 build 成功服务器编译错误

需要用 MariaDB 的 Python 包,能和 Leap 15.5 MariaDB 兼容的最后一个版本是 mariadb==1.0.11,在本地用 pip3.10 顺利安装成功,开发测试正常,部署到同为 Leap 15.5 但 Python 是 3.11 的服务器时出现奇怪的问题:

$ pip install mariadb==1.0.11
Collecting mariadb==1.0.11
  Using cached mariadb-1.0.11.zip (85 kB)
  Preparing metadata (setup.py) ... done
Building wheels for collected packages: mariadb
  Building wheel for mariadb (setup.py) ... error
  error: subprocess-exited-with-error
  
  × python setup.py bdist_wheel did not run successfully.
  │ exit code: 1
  ╰─> [38 lines of output]
      running bdist_wheel
      running build
      running build_py
      creating build
      creating build/lib.linux-x86_64-cpython-311
      creating build/lib.linux-x86_64-cpython-311/mariadb
      copying mariadb/__init__.py -> build/lib.linux-x86_64-cpython-311/mariadb
      creating build/lib.linux-x86_64-cpython-311/mariadb/constants
      copying mariadb/constants/__init__.py -> build/lib.linux-x86_64-cpython-311/mariadb/constants
      copying mariadb/constants/CLIENT.py -> build/lib.linux-x86_64-cpython-311/mariadb/constants
      copying mariadb/constants/INDICATOR.py -> build/lib.linux-x86_64-cpython-311/mariadb/constants
      copying mariadb/constants/CURSOR.py -> build/lib.linux-x86_64-cpython-311/mariadb/constants
      copying mariadb/constants/FIELD_TYPE.py -> build/lib.linux-x86_64-cpython-311/mariadb/constants
      running build_ext
      building 'mariadb._mariadb' extension
      creating build/temp.linux-x86_64-cpython-311
      creating build/temp.linux-x86_64-cpython-311/mariadb
      gcc -pthread -Wsign-compare -DNDEBUG -fmessage-length=0 -grecord-gcc-switches -O2 -Wall -D_FORTIFY_SOURCE=2 -fstack-protector-strong -funwind-tables -fasynchronous-unwind-tables -fstack-clash-protection -g -DOPENSSL_LOAD_CONF -fwrapv -fno-semantic-interposition -fmessage-length=0 -grecord-gcc-switches -O2 -Wall -D_FORTIFY_SOURCE=2 -fstack-protector-strong -funwind-tables -fasynchronous-unwind-tables -fstack-clash-protection -g -IVendor/ -fmessage-length=0 -grecord-gcc-switches -O2 -Wall -D_FORTIFY_SOURCE=2 -fstack-protector-strong -funwind-tables -fasynchronous-unwind-tables -fstack-clash-protection -g -IVendor/ -fPIC -DPY_MARIADB_MAJOR_VERSION=1 -DPY_MARIADB_MINOR_VERSION=0 -DPY_MARIADB_PATCH_VERSION=11 -I/usr/include/mysql -I/usr/include/mysql/mysql -I./include -I/home/ellis/fin/finenv/include -I/usr/include/python3.11 -c mariadb/mariadb.c -o build/temp.linux-x86_64-cpython-311/mariadb/mariadb.o -DDEFAULT_PLUGINS_SUBDIR=\"/usr/lib64/mysql/plugin/\"
      mariadb/mariadb.c: In function ‘PyInit__mariadb’:
      mariadb/mariadb.c:155:35: error: lvalue required as left operand of assignment
           Py_TYPE(&MrdbConnection_Type) = &PyType_Type;
                                         ^
      mariadb/mariadb.c:168:31: error: lvalue required as left operand of assignment
           Py_TYPE(&MrdbCursor_Type) = &PyType_Type;
                                     ^
      mariadb/mariadb.c:174:29: error: lvalue required as left operand of assignment
           Py_TYPE(&MrdbPool_Type) = &PyType_Type;
                                   ^
      mariadb/mariadb.c:180:34: error: lvalue required as left operand of assignment
           Py_TYPE(&MrdbIndicator_Type) = &PyType_Type;
                                        ^
      mariadb/mariadb.c:186:38: error: lvalue required as left operand of assignment
           Py_TYPE(&Mariadb_Fieldinfo_Type) = &PyType_Type;
                                            ^
      mariadb/mariadb.c:192:38: error: lvalue required as left operand of assignment
           Py_TYPE(&Mariadb_DBAPIType_Type) = &PyType_Type;
                                            ^
      error: command '/usr/bin/gcc' failed with exit code 1
      [end of output]
  
  note: This error originates from a subprocess, and is likely not a problem with pip.
  ERROR: Failed building wheel for mariadb
  Running setup.py clean for mariadb
Failed to build mariadb
ERROR: Could not build wheels for mariadb, which is required to install pyproject.toml-based projects

[notice] A new release of pip is available: 23.1.2 -> 23.2.1
[notice] To update, run: pip install --upgrade pip

如果真的有问题,这么大的 bug, MariaDB 的人不修好不会发新版本吧……救命啊,这要怎么解决?给 MariaDB 报错?老版本会修吗?关键是我在本地都好好的。

这个是 mariadb-connector-python?为什么不用 pymysql 啊。

他们确实修了啊,在 1.1.5 版本: https://jira.mariadb.org/browse/CONPY-201

1赞

感谢回复,我切回 pymysql 吧:sob:,一开始用的是它,但我想着用 C 写的 mariadb-connector-python 会不会快一点,现在看来还是纯 python 的靠谱。

新版本没法用的,API 和 Leap 15.5 的 libmariadb 不兼容。

本主题在最后一个回复创建后60分钟后自动锁定。不再允许添加新回复。

mariadb-connector-python 靠不靠谱我不知道,但是我知道 Oracle 的 mysql-connector-python 是菜鸟写的,网络编程的基本知识都无,坑死我了!