mysql - 尝试为我的 Python 3.7/Django 项目构建 Docker 映像时出现“OSError:mysql_config not found”
问题描述
我正在使用 Python 3.7 和 Django 2。我有以下 requirements.txt 文件,从我当前的项目中导出......
asgiref==3.2.3
Babel==2.8.0
Django==2.0
django-address==0.2.1
django-mysql==3.3.0
django-phonenumber-field==4.0.0
mysqlclient==1.4.6
phonenumbers==8.11.2
pycountry==19.8.18
pytz==2019.3
PyYAML==5.3
ruamel.yaml==0.16.6
ruamel.yaml.clib==0.2.0
sqlparse==0.3.0
我想创建一个 docker 映像来运行我的 Django 虚拟环境。我有这个 Dockerfile ...
FROM python:3.7-slim
RUN python -m pip install --upgrade pip
COPY requirements.txt requirements.txt
RUN python -m pip install -r requirements.txt
COPY . .
但是,当我尝试构建图像时出现此错误。我不确定这意味着什么。我可以毫无问题地运行服务器(python manage.py runserver 8000),所以不知道为什么我的虚拟环境正在死去......
(venv) localhost:web davea$ docker build .
Sending build context to Docker daemon 132.5MB
Step 1/5 : FROM python:3.7-slim
---> f2d2e1dc8c72
Step 2/5 : RUN python -m pip install --upgrade pip
---> Using cache
---> cf901765d254
Step 3/5 : COPY requirements.txt requirements.txt
---> Using cache
---> e4770d5b0c4a
Step 4/5 : RUN python -m pip install -r requirements.txt
---> Running in d4d937c92f06
Collecting asgiref==3.2.3
Downloading asgiref-3.2.3-py2.py3-none-any.whl (18 kB)
Collecting Babel==2.8.0
Downloading Babel-2.8.0-py2.py3-none-any.whl (8.6 MB)
Collecting Django==2.0
Downloading Django-2.0-py3-none-any.whl (7.1 MB)
Collecting django-address==0.2.1
Downloading django-address-0.2.1.tar.gz (16 kB)
Collecting django-mysql==3.3.0
Downloading django_mysql-3.3.0-py3-none-any.whl (63 kB)
Collecting django-phonenumber-field==4.0.0
Downloading django_phonenumber_field-4.0.0-py3-none-any.whl (51 kB)
Collecting mysqlclient==1.4.6
Downloading mysqlclient-1.4.6.tar.gz (85 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-2p1gjaea/mysqlclient/setup.py'"'"'; __file__='"'"'/tmp/pip-install-2p1gjaea/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-install-2p1gjaea/mysqlclient/pip-egg-info
cwd: /tmp/pip-install-2p1gjaea/mysqlclient/
Complete output (12 lines):
/bin/sh: 1: mysql_config: not found
/bin/sh: 1: mariadb_config: not found
/bin/sh: 1: mysql_config: not found
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/tmp/pip-install-2p1gjaea/mysqlclient/setup.py", line 16, in <module>
metadata, options = get_config()
File "/tmp/pip-install-2p1gjaea/mysqlclient/setup_posix.py", line 61, in get_config
libs = mysql_config("libs")
File "/tmp/pip-install-2p1gjaea/mysqlclient/setup_posix.py", line 29, in mysql_config
raise EnvironmentError("%s not found" % (_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.
解决方案
推荐阅读
- flutter - 在 Riverpod 中是否有相当于 bloc 的 buildwhen?
- html - Prettier 停止工作了
- sql-server - Perl:如何使用 perl 将数据从 SQL Server 导出到制表符分隔的 txt 文件中
- asp.net-core - 通过选中剃刀页面中的框来分配值
- c - 查找输入和堆栈中返回地址的位置之间的字节数
- qml - Qml ChartView 不会缩放到 X 轴的最大值
- javascript - 终止 javascript 执行
- flutter - 提交表单时,InAppWebView 颤振 shouldOverrideUrlLoading 不起作用
- python - 在带有 pybind11 的 Visual Studio 上使用 64 位 python
- r - 垂直 95% 置信区间图 2 组比较