且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Docker Alpine:加载 MySQLdb 模块时出错

更新时间:2021-08-20 22:27:21

您似乎缺少 MySQLdb Python 模块,您应该为该模块安装 mysqlclient Python包:pip install mysqlclient.

It seems you're missing the MySQLdb Python module, for which you should install the mysqlclient Python package: pip install mysqlclient.

在 Alpine 上,pip 将从源代码构建 mysqlclient,因此您需要 gccmusl-dev 用于此设置步骤,因此你需要将 apk del build-deps 推迟到 Python 模块安装之后.

On Alpine, pip will build mysqlclient from source, so you'll need gcc and musl-dev for this setup step, hence you'll need to postpone apk del build-deps to after Python modules are installed.

固定的 Dockerfile 片段:

Fixed Dockerfile snippet:

RUN apk update 
    && apk add --virtual build-deps gcc python3-dev musl-dev 
    && apk add --no-cache mariadb-dev

...

RUN pip install mysqlclient  

RUN apk del build-deps