Ubuntu 20.04 上的 MariaDB Connector/Python 安装问题 (

Ser*_*nin 0 python mariadb

我在 Ubuntu 20.04 上安装适用于 python 的 mariadb 连接器时遇到了问题。\n我确实安装了适用于 C 的 mariadb 服务器和连接器,正如文档中所述:

\n
sudo apt-get update        \nsudo apt-get install mariadb-server\nsudo apt-get install libmariadb3\nsudo apt-get install libmariadb-dev\n   \n
Run Code Online (Sandbox Code Playgroud)\n

还安装了:

\n
sudo apt-get install libmariadbclient-dev\n
Run Code Online (Sandbox Code Playgroud)\n

然后:

\n
$ pip3 install mariadb\nCollecting mariadb   Using cached mariadb-1.0.3.tar.gz (66 kB) Building wheels for collected packages: mariadb   Building wheel for mariadb (setup.py) ... error   ERROR: Command errored out with exit status 1:    command: /usr/bin/python3 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-01wak5oz/mariadb/setup.py'"'"';\n__file__='"'"'/tmp/pip-install-01wak5oz/mariadb/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\\r\\n'"'"', '"'"'\\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d /tmp/pip-wheel-oazbv39u\n       cwd: /tmp/pip-install-01wak5oz/mariadb/   Complete output (40 lines):   running bdist_wheel   running build   running build_py   creating build   creating build/lib.linux-x86_64-3.8   creating build/lib.linux-x86_64-3.8/mariadb   copying mariadb/__init__.py -> build/lib.linux-x86_64-3.8/mariadb   creating build/lib.linux-x86_64-3.8/mariadb/constants   copying mariadb/constants/__init__.py -> build/lib.linux-x86_64-3.8/mariadb/constants   copying mariadb/constants/CLIENT.py -> build/lib.linux-x86_64-3.8/mariadb/constants   copying mariadb/constants/INDICATOR.py -> build/lib.linux-x86_64-3.8/mariadb/constants   copying mariadb/constants/CURSOR.py -> build/lib.linux-x86_64-3.8/mariadb/constants   copying mariadb/constants/FIELD_TYPE.py -> build/lib.linux-x86_64-3.8/mariadb/constants   running build_ext   building 'mariadb._mariadb' extension   creating build/temp.linux-x86_64-3.8   creating build/temp.linux-x86_64-3.8/mariadb   x86_64-linux-gnu-gcc -pthread\n-Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -g -fwrapv -O2 -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -DPY_MARIADB_MAJOR_VERSION=1 -DPY_MARIADB_MINOR_VERSION=0 -DPY_MARIADB_PATCH_VERSION=3 -I/usr/include/mariadb -I/usr/include/mariadb/mysql -I./include -I/usr/include/python3.8 -c mariadb/mariadb.c -o build/temp.linux-x86_64-3.8/mariadb/mariadb.o\n-DDEFAULT_PLUGINS_SUBDIR="/usr/lib/x86_64-linux-gnu/mariadb19/plugin"   x86_64-linux-gnu-gcc -pthread -Wno-unused-result -Wsign-compare\n-DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -g -fwrapv -O2 -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -DPY_MARIADB_MAJOR_VERSION=1 -DPY_MARIADB_MINOR_VERSION=0 -DPY_MARIADB_PATCH_VERSION=3 -I/usr/include/mariadb -I/usr/include/mariadb/mysql -I./include -I/usr/include/python3.8 -c mariadb/mariadb_connection.c -o build/temp.linux-x86_64-3.8/mariadb/mariadb_connection.o\n-DDEFAULT_PLUGINS_SUBDIR="/usr/lib/x86_64-linux-gnu/mariadb19/plugin"   x86_64-linux-gnu-gcc -pthread -Wno-unused-result -Wsign-compare\n-DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -g -fwrapv -O2 -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -DPY_MARIADB_MAJOR_VERSION=1 -DPY_MARIADB_MINOR_VERSION=0 -DPY_MARIADB_PATCH_VERSION=3 -I/usr/include/mariadb -I/usr/include/mariadb/mysql -I./include -I/usr/include/python3.8 -c mariadb/mariadb_exception.c -o build/temp.linux-x86_64-3.8/mariadb/mariadb_exception.o\n-DDEFAULT_PLUGINS_SUBDIR="/usr/lib/x86_64-linux-gnu/mariadb19/plugin"   x86_64-linux-gnu-gcc -pthread -Wno-unused-result -Wsign-compare\n-DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -g -fwrapv -O2 -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -DPY_MARIADB_MAJOR_VERSION=1 -DPY_MARIADB_MINOR_VERSION=0 -DPY_MARIADB_PATCH_VERSION=3 -I/usr/include/mariadb -I/usr/include/mariadb/mysql -I./include -I/usr/include/python3.8 -c mariadb/mariadb_cursor.c -o build/temp.linux-x86_64-3.8/mariadb/mariadb_cursor.o\n-DDEFAULT_PLUGINS_SUBDIR="/usr/lib/x86_64-linux-gnu/mariadb19/plugin"   x86_64-linux-gnu-gcc -pthread -Wno-unused-result -Wsign-compare\n-DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -g -fwrapv -O2 -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -DPY_MARIADB_MAJOR_VERSION=1 -DPY_MARIADB_MINOR_VERSION=0 -DPY_MARIADB_PATCH_VERSION=3 -I/usr/include/mariadb -I/usr/include/mariadb/mysql -I./include -I/usr/include/python3.8 -c mariadb/mariadb_codecs.c -o build/temp.linux-x86_64-3.8/mariadb/mariadb_codecs.o\n-DDEFAULT_PLUGINS_SUBDIR="/usr/lib/x86_64-linux-gnu/mariadb19/plugin"   mariadb/mariadb_codecs.c: In function \xe2\x80\x98mariadb_extended_field_type\xe2\x80\x99:   mariadb/mariadb_codecs.c:64:5: error: unknown type name \xe2\x80\x98MARIADB_CONST_STRING\xe2\x80\x99\n     64 |     MARIADB_CONST_STRING str;\n        |     ^~~~~~~~~~~~~~~~~~~~   mariadb/mariadb_codecs.c:66:10: warning: implicit declaration of function \xe2\x80\x98mariadb_field_attr\xe2\x80\x99 [-Wimplicit-function-declaration]\n     66 |     if (!mariadb_field_attr(&str, field, MARIADB_FIELD_ATTR_FORMAT_NAME))\n        |          ^~~~~~~~~~~~~~~~~~   mariadb/mariadb_codecs.c:66:42: error: \xe2\x80\x98MARIADB_FIELD_ATTR_FORMAT_NAME\xe2\x80\x99 undeclared (first use in this function)\n     66 |     if (!mariadb_field_attr(&str, field, MARIADB_FIELD_ATTR_FORMAT_NAME))\n        |                                          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~   mariadb/mariadb_codecs.c:66:42: note: each undeclared identifier is reported only once for each function it appears in   mariadb/mariadb_codecs.c:68:14: error: request for member \xe2\x80\x98length\xe2\x80\x99 in something not a structure or union\n     68 |       if (str.length == 4 && !strncmp(str.str, "json", 4))\n        |              ^   mariadb/mariadb_codecs.c:68:42: error: request for member \xe2\x80\x98str\xe2\x80\x99 in something not a structure or union\n     68 |       if (str.length == 4 && !strncmp(str.str, "json", 4))\n        |                                          ^   error: command 'x86_64-linux-gnu-gcc' failed with exit status 1  \n----------------------------------------   ERROR: Failed building wheel for mariadb   Running setup.py clean for mariadb Failed to build mariadb\n
Run Code Online (Sandbox Code Playgroud)\n

看来问题来自于:

\n
  mariadb/mariadb_codecs.c: In function \xe2\x80\x98mariadb_extended_field_type\xe2\x80\x99:\n  mariadb/mariadb_codecs.c:64:5: error: unknown type name \xe2\x80\x98MARIADB_CONST_STRING\xe2\x80\x99\n
Run Code Online (Sandbox Code Playgroud)\n

但我不太擅长 C,无法立即调查此问题。\n尝试过谷歌搜索,但没有找到由 MARIADB_CONST_STRING 类型引起的问题的结果。

\n

这是我第一次在 ubuntu 上安装适用于 python 的 mariadb 连接器。\n以前有人见过这个错误吗?我应该如何进行?\n感谢您的建议。

\n

Ser*_*nin 5

我浏览了更多文档:https ://mariadb.com/kb/en/installing-mariadb-deb-files/

有帮助的是:

curl -sS https://downloads.mariadb.com/MariaDB/mariadb_repo_setup | sudo bash
Run Code Online (Sandbox Code Playgroud)

然后再说一遍:

$ sudo apt-get update
$ sudo apt-get install libmariadb3
Run Code Online (Sandbox Code Playgroud)

现在让我们尝试安装 Python mariadb lib:

$ pip3 install mariadb
Collecting mariadb
  Using cached mariadb-1.0.3.tar.gz (66 kB)
Building wheels for collected packages: mariadb
  Building wheel for mariadb (setup.py) ... done
  Created wheel for mariadb: filename=mariadb-1.0.3-cp38-cp38-linux_x86_64.whl size=233300 sha256=607a788847d8d023a8921f7fc8fa9a5450b0e7f0625416de86d26cedfe202e73
  Stored in directory: /home/sergey/.cache/pip/wheels/c5/56/1d/ade90f725a5f6a15b505bebc461ebfc573223e9836c5bf5603
Successfully built mariadb
Installing collected packages: mariadb
Successfully installed mariadb-1.0.3
Run Code Online (Sandbox Code Playgroud)