0

I'm trying to curl a txt file and pipe it to pip.

Example:

curl -s URL | pip install -r -

It doesn't work beucase the last - is not the curl output as I'd expect. I often have this issue with other commands too.

How to fix this with bash?

  • pip does not accept requirements from pipe/stdin – RomanPerekhrest Nov 4 '19 at 7:00
  • What do you mean does not accept? I thought this was a bash / linux thing, and transparent to whatever command you are running – Freedo Nov 4 '19 at 7:01
  • I remember I once had the same issue downloading a .sql file stored on the web (it's just plain text) and using it with mysql command to restore a backup. I think I had to use something like << together with - to work. I don't remember exactly and I lost the code because of power loss – Freedo Nov 4 '19 at 7:03
  • 1
    I'm not entirely sure what you're expecting to happen, but some of this is certainly not transparent to the command. In your command, pip receives the arguments "install", "-r", and "-". It is completely up to the pip executable how to interpret these. It also has the output of curl available on its standard input ("stdin"), so if it reads from that it'll get the downloaded file. If it doesn't read from stdin, it'll never see the downloaded file at all. – Gordon Davisson Nov 4 '19 at 7:53
  • 1
    @Freedo, using - to mean stdin is indeed a feature of the program in question, not that of the shell. The usual workaround is to use /dev/stdin. – ilkkachu Nov 4 '19 at 9:57
2

Using - as a method to pipeline information which could also come from a file is a fairly common way for things to work, but it is not a given.

I’m assuming your URL contains only a flat list of packages, IE no html:

pip install -r <(curl -s URL)

Or

pip install $(curl -s URL)
|improve this answer|||||
  • Yes this doesn't work for pip. But you can use /dev/stind as @ilkkachu said – Freedo Nov 4 '19 at 10:18
  • Apologies, I didn't have pip to hand to verify how -r behaves. Should be able to do this via <(...) -- answer edited. – bxm Nov 4 '19 at 10:57

Not the answer you're looking for? Browse other questions tagged or ask your own question.