question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Way to specify --no-deps option in requirements.txt?

See original GitHub issue

What’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.

  1. Install gcc inside 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-base packages just to install a single package in python.

  2. Use --no-deps option in Dockerfile:

    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 freeze or something, rather than specifying package names by hand.

Additional context

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
chrahuntcommented, Nov 15, 2019

Thank you for your understanding. Please don’t hesitate to share any other thoughts or issues. 😃

0reactions
hallazzangcommented, Nov 15, 2019

@chrahunt Thank you for response, I got your point and that suggestion would definitely work. I’ll close this issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Pass --no-deps in PIP requirements.txt - python - Stack Overflow
The best you can do is freeze everything from your master environment, and use "--no-deps" when you pip install. This is OK since...
Read more >
Pass --no-deps in PIP requirements txt | Edureka Community
I need to pass a flag of --no-deps to one of my packages in my requirements.txt file to ignore the dependencies of a...
Read more >
pip install - pip documentation v22.3.1
The install command has a --report option that will generate a JSON report of what pip has installed. In combination with the --dry-run...
Read more >
Manage required Python packages with requirements.txt
Use pip freeze > requirements.txt and manage python package ... dependency and add the --find-links <path> option to your requirements.txt:.
Read more >
User Guide — pip 10.0.0.dev0 documentation
Constraints files offer a better way: write a single constraints file for your ... pip allows you to set all command line option...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found