我在 django rest 框架中有一个小项目,我想对其进行 dockerize。在我的requirements.txt
文件中有一个名为ruamel.yaml.clib==0.2.6
. 虽然下载所有其他要求成功,但在尝试下载此包时出现问题。
#11 208.5 Collecting ruamel.yaml.clib==0.2.6
#11 208.7 Downloading ruamel.yaml.clib-0.2.6.tar.gz (180 kB)
#11 217.8 ERROR: Command errored out with exit status 1:
#11 217.8 command: /usr/local/bin/python -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-b8oectgw/ruamel-yaml-clib_517e9b3f18a94ebea71ec88fbaece43a/setup.py'"'"'; __file__='"'"'/tmp/pip-install-b8oectgw/ruamel-yaml-clib_517e9b3f18a94ebea71ec88fbaece43a/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-pip-egg-info-n2gr5j35
#11 217.8 cwd: /tmp/pip-install-b8oectgw/ruamel-yaml-clib_517e9b3f18a94ebea71ec88fbaece43a/
#11 217.8 Complete output (3 lines):
#11 217.8 sys.argv ['/tmp/pip-install-b8oectgw/ruamel-yaml-clib_517e9b3f18a94ebea71ec88fbaece43a/setup.py', 'egg_info', '--egg-base', '/tmp/pip-pip-egg-info-n2gr5j35']
#11 217.8 test compiling /tmp/tmp_ruamel_erx3efla/test_ruamel_yaml.c -> test_ruamel_yaml compile error: /tmp/tmp_ruamel_erx3efla/test_ruamel_yaml.c
#11 217.8 Exception: command 'gcc' failed: No such file or directory
#11 217.8 ----------------------------------------
#11 217.8 WARNING: Discarding https://files.pythonhosted.org/packages/8b/25/08e5ad2431a028d0723ca5540b3af6a32f58f25e83c6dda4d0fcef7288a3/ruamel.yaml.clib-0.2.6.tar.gz#sha256=4ff604ce439abb20794f05613c374759ce10e3595d1867764dd1ae675b85acbd (from https://pypi.org/simple/ruamel-yaml-clib/) (requires-python:>=3.5). Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
#11 217.8 ERROR: Could not find a version that satisfies the requirement ruamel.yaml.clib==0.2.6 (from versions: 0.1.0, 0.1.2, 0.2.0, 0.2.2, 0.2.3, 0.2.4, 0.2.6)
#11 217.8 ERROR: No matching distribution found for ruamel.yaml.clib==0.2.6
但是,我在没有docker的情况下下载这个包是没有问题的。有什么建议?
这是 Dockerfile:
FROM python:3-alpine
# set work directory
WORKDIR /usr/src/app
# set environment variables
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
# install dependencies
RUN pip install -U pip setuptools wheel ruamel.yaml ruamel.yaml.clib==0.2.6
COPY ./requirements.txt .
RUN pip install --default-timeout=100 -r requirements.txt
# copy project
COPY . .
这是撰写文件
version: '3.8'
services:
web:
build: .
command: python manage.py runserver 0.0.0.0:8000
volumes:
- .:/usr/src/app
ports:
- 8000:8000
env_file:
- ./.env.dev
编辑
正如@Anthon 在评论中提到的,问题与高山有关。我python:3.9-slim-buster
在 Dockerfile 中使用了,问题解决了!
我认为问题在于您Dockerfile
尝试安装ruamel.yaml.clib
. 它应该使用 pip 安装(就像 中记录的那样ruamel.yaml
)。
我建议你把它从 requirements.txt 中取出并明确地做一个
pip install -U pip setuptools wheel ruamel.yaml.clib==0.2.6
在你的Dockerfile
代替。这应该只是让你获得预编译的轮子,而不是尝试ruamel.yaml.clib
从源代码编译,如果你没有安装 C 编译器,这将不起作用(这实际上是 docker 抱怨的)
我有 ruamel.yaml.clib 在多个 Docker 容器中成功运行(但我从不使用requirements.txt
)
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句