You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

无法pip安装Python的MariaDB库,Docker及本地环境均报错求助

问题求助

查了相关主题的帖子,但仍有知识盲区无法理清问题全貌。

目标

需要从简单应用(本地或Docker容器)访问远程服务器上的MariaDB数据库,执行若干查询脚本。选择Docker是因为它更简洁,不易受本地系统干扰,但无论在本地MacOS还是Docker的Linux环境中,均出现相同错误。

当前Dockerfile(未添加MariaDB相关配置时应用运行正常)

FROM python:3.8

WORKDIR /usr/src/app

RUN apt-get update
RUN apt-get install libmariadb3 libmariadb-dev

COPY . .

RUN pip install --upgrade pip
RUN pip install --upgrade setuptools
RUN pip install --no-cache-dir -r requirements.txt

EXPOSE 5000

CMD ["python", "./app.py"]

requirements.txt(Flask仅用于验证pip安装,实际可成功安装)

Flask==2.0.2
mariadb==1.1.4

Docker Build时的错误信息

RUN pip install --no-cache-dir -r requirements.txt:                                                                 
#11 1.253 Collecting Flask==2.0.2                                                                                            
#11 1.397   Downloading Flask-2.0.2-py3-none-any.whl (95 kB)                                                                 
#11 1.441      ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 95.2/95.2 kB 4.7 MB/s eta 0:00:00                                    
#11 1.527 Collecting mariadb==1.1.4                                                                                          
#11 1.558   Downloading mariadb-1.1.4.zip (97 kB)
#11 1.568      ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 97.4/97.4 kB 32.3 MB/s eta 0:00:00
#11 1.585   Preparing metadata (setup.py): started
#11 1.920   Preparing metadata (setup.py): finished with status 'error'
#11 1.930   error: subprocess-exited-with-error
#11 1.930   
#11 1.930   × python setup.py egg_info did not run successfully.
#11 1.930   │ exit code: 1
#11 1.930   ╰─> [8 lines of output]
#11 1.930       Traceback (most recent call last):
#11 1.930         File "<string>", line 2, in <module>
#11 1.930         File "<pip-setuptools-caller>", line 34, in <module>
#11 1.930         File "/tmp/pip-install-p7s8jj6d/mariadb_90e5111808594b418ebf9c5df54e9d58/setup.py", line 27, in <module>
#11 1.930           cfg = get_config(options)
#11 1.930         File "/tmp/pip-install-p7s8jj6d/mariadb_90e5111808594b418ebf9c5df54e9d58/mariadb_posix.py", line 64, in get_config
#11 1.930           print('MariaDB Connector/Python requires MariaDB Connector/C '
#11 1.930       TypeError: not enough arguments for format string
#11 1.930       [end of output]
#11 1.930   
#11 1.930   note: This error originates from a subprocess, and is likely not a problem with pip.
#11 1.933 error: metadata-generation-failed
#11 1.933 
#11 1.933 × Encountered error while generating package metadata.
#11 1.933 ╰─> See above for output.
#11 1.933 
#11 1.933 note: This is an issue with the package mentioned above, not pip.
#11 1.933 hint: See above for details.
------
executor failed running [/bin/sh -c pip install --no-cache-dir -r requirements.txt]: exit code: 1

问题卡点

显然MariaDB Connector/C存在问题,但不清楚具体原因。原本以为apt-get install libmariadb3 libmariadb-dev可以安装正确的连接器,但事实并非如此。尝试在执行pip命令前手动在容器中安装Connector/C时,发现有大量版本和文件可选,完全不知道该选择哪一个,也不清楚安装方法,恳请帮助。

内容的提问来源于stack exchange,提问作者DangerPaws

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.16 14:05:23