gpt4 book ai didi

python - 无法在 docker mysql 容器中安装 mysqlclient

转载 作者:行者123 更新时间:2023-11-29 09:59:23 25 4
gpt4 key购买 nike

在由 mysql 优化的 Docker 镜像 (mysql/mysql-server) 制作的 Docker 容器中安装 mysqlclient 时遇到一些问题。该容器在 Oracle Linux Sysrem (CentOS) 上运行。

错误看起来像这样

Installing collected packages: mysqlclient, raven, redis, xmltodict, responses
Running setup.py install for mysqlclient ... error
Complete output from command /tracking_api/tracking/bin/python3.6 -u -c "import setuptools, tokenize;__file__='/tmp/pip-install-z_jafqw3/mysqlclient/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-record-vqelrf7r/install-record.txt --single-version-externally-managed --compile --install-headers /tracking_api/tracking/include/site/python3.6/mysqlclient:
running install
running build
running build_py
creating build
creating build/lib.linux-x86_64-3.6
copying _mysql_exceptions.py -> build/lib.linux-x86_64-3.6
creating build/lib.linux-x86_64-3.6/MySQLdb
copying MySQLdb/__init__.py -> build/lib.linux-x86_64-3.6/MySQLdb
copying MySQLdb/compat.py -> build/lib.linux-x86_64-3.6/MySQLdb
copying MySQLdb/connections.py -> build/lib.linux-x86_64-3.6/MySQLdb
copying MySQLdb/converters.py -> build/lib.linux-x86_64-3.6/MySQLdb
copying MySQLdb/cursors.py -> build/lib.linux-x86_64-3.6/MySQLdb
copying MySQLdb/release.py -> build/lib.linux-x86_64-3.6/MySQLdb
copying MySQLdb/times.py -> build/lib.linux-x86_64-3.6/MySQLdb
creating build/lib.linux-x86_64-3.6/MySQLdb/constants
copying MySQLdb/constants/__init__.py -> build/lib.linux-x86_64-3.6/MySQLdb/constants
copying MySQLdb/constants/CLIENT.py -> build/lib.linux-x86_64-3.6/MySQLdb/constants
copying MySQLdb/constants/CR.py -> build/lib.linux-x86_64-3.6/MySQLdb/constants
copying MySQLdb/constants/ER.py -> build/lib.linux-x86_64-3.6/MySQLdb/constants
copying MySQLdb/constants/FIELD_TYPE.py -> build/lib.linux-x86_64-3.6/MySQLdb/constants
copying MySQLdb/constants/FLAG.py -> build/lib.linux-x86_64-3.6/MySQLdb/constants
copying MySQLdb/constants/REFRESH.py -> build/lib.linux-x86_64-3.6/MySQLdb/constants
running build_ext
building '_mysql' extension
creating build/temp.linux-x86_64-3.6
gcc -pthread -Wno-unused-result -Wsign-compare -DDYNAMIC_ANNOTATIONS_ENABLED=1 -DNDEBUG -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -fPIC -Dversion_info=(1,3,12,'final',0) -D__version__=1.3.12 -I/usr/include/mysql -I/tracking_api/tracking/include -I/usr/include/python3.6m -c _mysql.c -o build/temp.linux-x86_64-3.6/_mysql.o -m64
unable to execute 'gcc': No such file or directory
error: command 'gcc' failed with exit status 1

----------------------------------------
Command "/tracking_api/tracking/bin/python3.6 -u -c "import setuptools, tokenize;__file__='/tmp/pip-install-z_jafqw3/mysqlclient/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-record-vqelrf7r/install-record.txt --single-version-externally-managed --compile --install-headers /tracking_api/tracking/include/site/python3.6/mysqlclient" failed with error code 1 in /tmp/pip-install-z_jafqw3/mysqlclient/

我注意到该问题是由于容器中没有 gcc 引起的。使用 yum install gcc 安装 gcc 后,我收到了另一个如下所示的错误

Installing collected packages: mysqlclient, raven, redis, xmltodict, responses
Running setup.py install for mysqlclient ... error
Complete output from command /tracking_api/tracking/bin/python3.6 -u -c "import setuptools, tokenize;__file__='/tmp/pip-install-90ek02_q/mysqlclient/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-record-rdg1c3go/install-record.txt --single-version-externally-managed --compile --install-headers /tracking_api/tracking/include/site/python3.6/mysqlclient:
running install
running build
running build_py
creating build
creating build/lib.linux-x86_64-3.6
copying _mysql_exceptions.py -> build/lib.linux-x86_64-3.6
creating build/lib.linux-x86_64-3.6/MySQLdb
copying MySQLdb/__init__.py -> build/lib.linux-x86_64-3.6/MySQLdb
copying MySQLdb/compat.py -> build/lib.linux-x86_64-3.6/MySQLdb
copying MySQLdb/connections.py -> build/lib.linux-x86_64-3.6/MySQLdb
copying MySQLdb/converters.py -> build/lib.linux-x86_64-3.6/MySQLdb
copying MySQLdb/cursors.py -> build/lib.linux-x86_64-3.6/MySQLdb
copying MySQLdb/release.py -> build/lib.linux-x86_64-3.6/MySQLdb
copying MySQLdb/times.py -> build/lib.linux-x86_64-3.6/MySQLdb
creating build/lib.linux-x86_64-3.6/MySQLdb/constants
copying MySQLdb/constants/__init__.py -> build/lib.linux-x86_64-3.6/MySQLdb/constants
copying MySQLdb/constants/CLIENT.py -> build/lib.linux-x86_64-3.6/MySQLdb/constants
copying MySQLdb/constants/CR.py -> build/lib.linux-x86_64-3.6/MySQLdb/constants
copying MySQLdb/constants/ER.py -> build/lib.linux-x86_64-3.6/MySQLdb/constants
copying MySQLdb/constants/FIELD_TYPE.py -> build/lib.linux-x86_64-3.6/MySQLdb/constants
copying MySQLdb/constants/FLAG.py -> build/lib.linux-x86_64-3.6/MySQLdb/constants
copying MySQLdb/constants/REFRESH.py -> build/lib.linux-x86_64-3.6/MySQLdb/constants
running build_ext
building '_mysql' extension
creating build/temp.linux-x86_64-3.6
gcc -pthread -Wno-unused-result -Wsign-compare -DDYNAMIC_ANNOTATIONS_ENABLED=1 -DNDEBUG -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -fPIC -Dversion_info=(1,3,12,'final',0) -D__version__=1.3.12 -I/usr/include/mysql -I/tracking_api/tracking/include -I/usr/include/python3.6m -c _mysql.c -o build/temp.linux-x86_64-3.6/_mysql.o -m64
_mysql.c:29:19: fatal error: mysql.h: No such file or directory
#include "mysql.h"
^
compilation terminated.
error: command 'gcc' failed with exit status 1

----------------------------------------
Command "/tracking_api/tracking/bin/python3.6 -u -c "import setuptools, tokenize;__file__='/tmp/pip-install-90ek02_q/mysqlclient/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-record-rdg1c3go/install-record.txt --single-version-externally-managed --compile --install-headers /tracking_api/tracking/include/site/python3.6/mysqlclient" failed with error code 1 in /tmp/pip-install-90ek02_q/mysqlclient/

我意识到这是由于 mysql.h 不存在造成的。我在这个question中找到了,我可以检查文件是否存在。但是,/use/local/目录中似乎不存在mysql文件夹。

这就是引起我困惑的原因。有谁知道为什么会发生这种情况?当docker镜像本身是mysql优化时,为什么没有mysql.h文件?提前致谢。

最佳答案

您需要安装mysql-community-develmysql.h就在这个包中。

注意:您需要先卸载mysql-community-server-minimal,并在mysqlclient安装完成后重新安装。否则,您将遇到以下冲突:

Transaction check error: file /usr/bin/mysql_config from install of mysql-community-devel-8.0.13-1.el7.x86_64 conflicts with file from package mysql-community-server-minimal-8.0.13-1.el7.x86_64

步骤如下:(省略pip install)

yum remove -y mysql-community-server-minimal
yum install -y gcc
yum install -y mysql-community-devel
pip install mysqlclient
yum remove -y mysql-community-devel
yum install -y mysql-community-server-minimal

mysqlclient安装的输出:

# pip install mysqlclientCollecting mysqlclient  Using cached https://files.pythonhosted.org/packages/ec/fd/83329b9d3e14f7344d1cb31f128e6dbba70c5975c9e57896815dbb1988ad/mysqlclient-1.3.13.tar.gzInstalling collected packages: mysqlclient  Running setup.py install for mysqlclient ... doneSuccessfully installed mysqlclient-1.3.13You are using pip version 8.1.2, however version 18.1 is available.You should consider upgrading via the 'pip install --upgrade pip' command.

最后,你的最后一个问题:

Why isn't there a mysql.h file when the docker image itself is mysql optimized

在dockerhub上,可以找到mysql/mysqlserver dockerfile的链接,位于 here :

FROM oraclelinux:7-slimARG MYSQL_SERVER_PACKAGE=mysql-community-server-minimal-8.0.13ARG MYSQL_SHELL_PACKAGE=mysql-shell-8.0.13# Install serverRUN yum install -y https://repo.mysql.com/mysql-community-minimal-release-el7.rpm \      https://repo.mysql.com/mysql-community-release-el7.rpm \  && yum-config-manager --enable mysql80-server-minimal \  && yum install -y \      $MYSQL_SERVER_PACKAGE \      $MYSQL_SHELL_PACKAGE \      libpwquality \  && yum clean all \  && mkdir /docker-entrypoint-initdb.dVOLUME /var/lib/mysqlCOPY docker-entrypoint.sh /entrypoint.shCOPY healthcheck.sh /healthcheck.shENTRYPOINT ["/entrypoint.sh"]HEALTHCHECK CMD /healthcheck.shEXPOSE 3306 33060CMD ["mysqld"]

从上面可以看出,它只是使用了预构建的mysql服务器包,没有编译mysql服务器的源代码,因此不需要mysql.h,仅在源码构建时使用。

但是当你安装mysqlclient时使用pip,因为mysqlclient python包有C扩展依赖,所以它必须使用 gcc来构建,那么它需要mysql.h,这给你带来了麻烦。安装mysql.h后一切正常。

关于python - 无法在 docker mysql 容器中安装 mysqlclient,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53312683/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com