Pip: Add the feature to read requirements.txt from stdin

Created on 29 Jul 2016  Â·  8Comments  Â·  Source: pypa/pip

Feature request: currently, pip install -r requirements.txt works, but pip install -r - does not. The latter should take the file contents from stdin. This will allow UNIX-style command chaining if the requirements are dynamically generated by a program. Of course it is easily fixed by xargs, but still.

auto-locked

Most helpful comment

@vmarkovtsev echo "pep8" | pip install -r /dev/stdin should work fine

All 8 comments

@vmarkovtsev echo "pep8" | pip install -r /dev/stdin should work fine

Hehe, yes, didn't think about it, thanks. But will not work on Windows.

I'm going to close this issue, there are a number of ways to achieve this and I don't believe that in general a requirements.txt from stdin makes a whole lot of sense to begin with.

FWIW, I found this issue a while back when I needed to do this in my dockerfile, so I could skip the -e . line that I have installing my local package, to keep my dependencies in a separate layer that wouldn't be invalidated as quickly.

The workaround above worked fine for me, though. My Dockerfile line is currently just:

RUN grep -v '^-e .' requirements.txt | pip install -r /dev/stdin

FWIW, another workaround from inside bash (and similar shells with process substitution):

pip install -r <(CMDs…)

@dstufft I need it to dynamically change a requirement on a certain platform (WSL) from the default version to a git hosted fork. In general it makes sense if you don't want to maintain separate nearly identically requirements files. Oh and it allows one to simply concatenate several requirements files, say you have one requirements.txt for running a project and one with the additional packages for developement (dev_requirements.txt, think of npm's devDependencies) so for setting up an environment for running you just run pip install -r requirements.txt and if you want to develop as well you run pip install -r <(cat requirements.txt dev_requirements.txt), if reading from stdin was possible then you could change that into cat requirements.txt dev_requirements.txt | pip install -r - which follow more traditional UNIX userland tools style.

An extension of the above.

pip3.6 install -r <(cat <<REQUIREMENTS
ansible==2.4.3.0
REQUIREMENTS)

Thanks for all idea... I use pip install -U -r <(pip list --outdated --format=freeze | sed 's/==/>=/') and it works...

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings