I have a small project in django rest framework and I want to dockerize it. In my requirements.txt
file there is a package called ruamel.yaml.clib==0.2.6
. While downloading all other requirements is successfull, there is a problem when it tries to download this package.
#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
However, there is no problem when I download this package without docker. Any suggestions?
Here is 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 . .
Here is compose file
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
EDIT
As mentioned in comments by @Anthon, the problem was related to alpine. I used python:3.9-slim-buster
instead in Dockerfile and problem solved!
CodePudding user response:
I think the problem is with the way your Dockerfile
tries to install ruamel.yaml.clib
. It should be installed using pip (just as documented for the ruamel.yaml
).
I suggest you take it out of the requirements.txt and explicitly do a
pip install -U pip setuptools wheel ruamel.yaml.clib==0.2.6
in your Dockerfile
instead. This should just get you the pre-compiled wheel instead of trying to compile ruamel.yaml.clib
from source, which will not work if you don't have a C compiler installed (this is actually what docker complains about)
I have ruamel.yaml.clib running succesfully in multiple Docker containers (but I never use a requirements.txt
)