首页 > 解决方案 > 从 python-alpine 安装 MySQL-python 失败

问题描述

我将通过以下 Dockerfile 构建一个 docker 镜像:

FROM python:2.7-alpine
RUN set -ex \
        && apk --no-cache add --virtual build-dependencies \
        && pip install --no-cache-dir mysql-python

它通过以下方式下载包:

Downloading https://files.pythonhosted.org/packages/a5/e9/51b544da85a36a68debe7a7091f068d802fc515a3a202652828c73453cad/MySQL-python-1.2.5.zip (108kB)

并执行

python setup.py install

但它失败并返回以下错误:

_mysql.c: In function '_mysql_ConnectionObject_ping':
_mysql.c:2005:41: error: 'MYSQL {aka struct st_mysql}' has no member named 'reconnect'
  if ( reconnect != -1 ) self->connection.reconnect = reconnect;
                                         ^
error: command 'gcc' failed with exit status 1

但是当我尝试:

FROM python:2.7

它非常有效。任何想法?

标签: pythonmysqldocker

解决方案


解决方案是使用mysqlclient包而不是 MySQL-python,它是一个解决当前 MySQL-python 存在的多个问题的 fork。

https://github.com/PyMySQL/mysqlclient-python


推荐阅读