gpt4 book ai didi

python - 在docker中使用pip安装python mysqlclient时出现 'OSError: mysql_config not found'错误

转载 作者:行者123 更新时间:2023-12-02 19:45:34 28 4
gpt4 key购买 nike

这是docker-compose build的完整输出

$ docker-compose build
db uses an image, skipping
Building module1
Step 1/6 : FROM python:3.8.5-alpine
---> 44fceb565b2a
Step 2/6 : WORKDIR /usr/src/module1
---> Using cache
---> c1804c812bc9
Step 3/6 : COPY ./requirements.txt /usr/src/module1/requirements.txt
---> Using cache
---> 993eed44a4a2
Step 4/6 : RUN pip install -r requirements.txt
---> Running in d9a8746b6746
Collecting click==7.1.2
Downloading click-7.1.2-py2.py3-none-any.whl (82 kB)
Collecting Flask==1.1.2
Downloading Flask-1.1.2-py2.py3-none-any.whl (94 kB)
Collecting Flask-Cors==3.0.8
Downloading Flask_Cors-3.0.8-py2.py3-none-any.whl (14 kB)
Collecting Flask-SQLAlchemy==2.4.4
Downloading Flask_SQLAlchemy-2.4.4-py2.py3-none-any.whl (17 kB)
Collecting itsdangerous==1.1.0
Downloading itsdangerous-1.1.0-py2.py3-none-any.whl (16 kB)
Collecting Jinja2==2.11.2
Downloading Jinja2-2.11.2-py2.py3-none-any.whl (125 kB)
Collecting MarkupSafe==1.1.1
Downloading MarkupSafe-1.1.1.tar.gz (19 kB)
Collecting mysqlclient==2.0.1
Downloading mysqlclient-2.0.1.tar.gz (87 kB)
ERROR: Command errored out with exit status 1:
command: /usr/local/bin/python -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-1bev77us/mysqlclient/setup.py'"'"'; __file__='"'"'/tmp/pip-install-1bev77us/mysqlclient/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-pip-egg-info-ebifvu4a
cwd: /tmp/pip-install-1bev77us/mysqlclient/
Complete output (12 lines):
/bin/sh: mysql_config: not found
/bin/sh: mariadb_config: not found
/bin/sh: mysql_config: not found
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/tmp/pip-install-1bev77us/mysqlclient/setup.py", line 15, in <module>
metadata, options = get_config()
File "/tmp/pip-install-1bev77us/mysqlclient/setup_posix.py", line 65, in get_config
libs = mysql_config("libs")
File "/tmp/pip-install-1bev77us/mysqlclient/setup_posix.py", line 31, in mysql_config
raise OSError("{} not found".format(_mysql_config_path))
OSError: mysql_config not found
----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
ERROR: Service 'module1' failed to build: The command '/bin/sh -c pip install -r requirements.txt' returned a non-zero code: 1
我的 Dockerfile看起来像这样:
FROM python:3.8.5-alpine

WORKDIR /usr/src/module1
COPY ./requirements.txt /usr/src/module1/requirements.txt
RUN pip install -r requirements.txt
COPY . /usr/src/module1
CMD ["python", "app.py"]
我在macOS中使用 mysql@5.7
我已经做了 https://github.com/clips/pattern/issues/203
有人可以告诉我如何解决这个问题吗?

最佳答案

一些python软件包依赖于系统上安装的软件。
mysql客户端就是其中之一。因此,您需要先安装它,然后再安装python软件包。当您使用 Alpine 时,可以通过添加RUN apk update && apk add mysql-client来实现:

FROM python:3.8.5-alpine

WORKDIR /usr/src/module1
COPY ./requirements.txt /usr/src/module1/requirements.txt
RUN apk update && apk add mysql-client
RUN pip install -r requirements.txt
COPY . /usr/src/module1
CMD ["python", "app.py"]

关于python - 在docker中使用pip安装python mysqlclient时出现 'OSError: mysql_config not found'错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63464534/

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