运行pip install mariadb遇TypeError错误,请求技术协助
解决
pip install mariadb时的TypeError: not enough arguments for format string报错 错误复现
执行pip install mariadb时出现以下报错:
Defaulting to user installation because normal site-packages is not writeable Collecting mariadb Using cached mariadb-1.1.4.zip (97 kB) Preparing metadata (setup.py) ... error error: subprocess-exited-with-error × python setup.py egg_info did not run successfully. │ exit code: 1 ╰─> [8 lines of output] Traceback (most recent call last): File "<string>", line 2, in <module> File "<pip-setuptools-caller>", line 34, in <module> File "/tmp/pip-install-6kwo2pga/mariadb_84568c03780743cba30d255711f92d08/setup.py", line 27, in <module> cfg = get_config(options) File "/tmp/pip-install-6kwo2pga/mariadb_84568c03780743cba30d255711f92d08/mariadb_posix.py", line 64, in get_config print('MariaDB Connector/Python requires MariaDB Connector/C ' TypeError: not enough arguments for format string [end of output] note: This error originates from a subprocess, and is likely not a problem with pip. error: metadata-generation-failed × Encountered error while generating package metadata. ╰─> See above for output. note: This is an issue with the package mentioned above, not pip. hint: See above for details.
解决方案
1. 安装兼容版本的mariadb Python包
你当前安装的1.1.4版本存在格式化字符串bug,升级到较新的稳定版本即可修复:
# 安装指定稳定版 pip install mariadb==2.0.6 # 或直接安装最新版 pip install --upgrade mariadb
2. 手动指定MariaDB Connector/C路径
如果已安装Connector/C但系统未自动识别路径,设置环境变量后再安装:
# Debian/Ubuntu系统通用路径,可根据实际安装位置调整 export C_INCLUDE_PATH=/usr/include/mariadb export LIBRARY_PATH=/usr/lib/x86_64-linux-gnu pip install mariadb
3. 使用系统包管理器安装(推荐)
直接通过系统包管理器安装Python的mariadb绑定,自动处理依赖兼容问题:
sudo apt install python3-mariadb
错误原因
这个报错主要有两个诱因:
- 旧版本的mariadb Python包(如1.1.4)在检测Connector/C版本时存在格式化字符串语法错误,新版本已修复该bug;
- MariaDB Connector/C的安装路径未被pip的安装脚本正确识别,导致触发错误提示时的字符串格式化失败。
内容的提问来源于stack exchange,提问作者RidiX
相关产品推荐
相关产品推荐

