Way to specify --no-deps option in requirements.txt?
See original GitHub issueWhat’s the problem this feature will solve?
I was trying to dockerize my python application that uses aioredis package.
I specified the requirement in requirements.txt as:
...
aioredis==1.3.0
And my Dockerfile looks like:
FROM python:3.8-alpine
WORKDIR /app
COPY requirements.txt .
RUN pip install -r requirements.txt
COPY . .
CMD ["python", "main.py"]
But then I get this error when building the image:
...
Running setup.py install for hiredis: started
Running setup.py install for hiredis: finished with status 'error'
ERROR: Command errored out with exit status 1:
command: /usr/local/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-yr8xwxtb/hiredis/setup.py'"'"'; __file__='"'"'/tmp/pip-install-yr8xwxtb/hiredis/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-zhb51yho/install-record.txt --single-version-externally-managed --compile
cwd: /tmp/pip-install-yr8xwxtb/hiredis/
Complete output (17 lines):
running install
running build
running build_py
creating build
creating build/lib.linux-x86_64-3.8
creating build/lib.linux-x86_64-3.8/hiredis
copying hiredis/__init__.py -> build/lib.linux-x86_64-3.8/hiredis
copying hiredis/version.py -> build/lib.linux-x86_64-3.8/hiredis
running build_ext
building 'hiredis.hiredis' extension
creating build/temp.linux-x86_64-3.8
creating build/temp.linux-x86_64-3.8/src
creating build/temp.linux-x86_64-3.8/vendor
creating build/temp.linux-x86_64-3.8/vendor/hiredis
gcc -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -DTHREAD_STACK_SIZE=0x100000 -fPIC -Ivendor -I/usr/local/include/python3.8 -c src/hiredis.c -o build/temp.linux-x86_64-3.8/src/hiredis.o
unable to execute 'gcc': No such file or directory
error: command 'gcc' failed with exit status 1
----------------------------------------
ERROR: Command errored out with exit status 1: /usr/local/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-yr8xwxtb/hiredis/setup.py'"'"'; __file__='"'"'/tmp/pip-install-yr8xwxtb/hiredis/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-zhb51yho/install-record.txt --single-version-externally-managed --compile Check the logs for full command output.
So I think this is because inside the alpine based container, there is no gcc available and thus what I can do is to install gcc manually inside the container(using RUN) or install aioredis without hiredis dependency(using --no-deps pip option).
I’d prefer latter one, but it seems impossible to achieve with current version of pip when using requirements.txt.
Describe the solution you’d like
Add an option to specify --no-deps per requirement.
Alternative Solutions As I said above, there are two alternative solutions for now.
-
Install
gccinside the container:FROM python:3.8-alpine RUN apk update && apk add build-base # added this line WORKDIR /app COPY requirements.txt . RUN pip install -r requirements.txt COPY . . CMD ["python", "main.py"]It works well, but I don’t want to install whole
build-basepackages just to install a single package in python. -
Use
--no-depsoption inDockerfile:FROM python:3.8-alpine WORKDIR /app COPY requirements.txt . RUN pip install -r requirements.txt --no-deps # added --no-deps option here COPY . . CMD ["python", "main.py"]But in this approach I have to specify full requirements list using
pip freezeor something, rather than specifying package names by hand.
Additional context
Issue Analytics
- State:
- Created 4 years ago
- Comments:7 (7 by maintainers)
Top Related StackOverflow Question
Thank you for your understanding. Please don’t hesitate to share any other thoughts or issues. 😃
@chrahunt Thank you for response, I got your point and that suggestion would definitely work. I’ll close this issue.