Docker构建镜像时MariaDB Connector/C版本不兼容问题求助
解决MariaDB Connector/Python安装版本不兼容问题
问题场景
用户尝试构建的Dockerfile如下:
FROM python:3.10 ENV TZ Europa/Berlin # install google chrome RUN wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - RUN sh -c 'echo \"deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main\" >> /etc/apt/sources.list.d/google-chrome.list' RUN apt-get -y update RUN apt-get install -y google-chrome-stable # install chromedriver RUN apt-get install -yqq unzip RUN wget -O /tmp/chromedriver.zip http://chromedriver.storage.googleapis.com/`curl -sS chromedriver.storage.googleapis.com/LATEST_RELEASE`/chromedriver_linux64.zip RUN unzip /tmp/chromedriver.zip chromedriver -d /usr/local/bin/ # set display port to avoid crash ENV DISPLAY=:99 # upgrade pip RUN pip install --upgrade pip # install selenium RUN pip install selenium # install mariadb RUN apt-get install -y libmariadb-dev RUN pip install mariadb
执行构建时,安装mariadb Python库出现以下错误:
"MariaDB Connector/Python requires MariaDB Connector/C >= 3.2.4, found version 3.1.16"
解决方法
系统默认软件源中的libmariadb-dev版本过低,无法满足Python连接器的依赖要求。需要添加MariaDB官方源来获取符合版本的Connector/C,修改Dockerfile中MariaDB相关的安装步骤:
# 安装依赖并添加MariaDB官方源 RUN apt-get install -y apt-transport-https curl RUN curl -LsS https://r.mariadb.com/downloads/mariadb_repo_setup | bash -s -- --mariadb-server-version=10.11 # 更新源后安装符合要求的libmariadb-dev RUN apt-get update && apt-get install -y libmariadb-dev # 安装mariadb Python连接器 RUN pip install mariadb
关键说明
- 使用官方脚本添加MariaDB源,指定
10.11版本的服务器包,对应的Connector/C版本会自动满足>=3.2.4的要求 - 替换原有的
apt-get install -y libmariadb-dev步骤,确保安装的是高版本依赖
内容的提问来源于stack exchange,提问作者Lord_HaHaHa
相关产品推荐
相关产品推荐

