-2

quick question - I have a big requirements file. On one system, I have a couple requirements (pytorch, torchvision) which don't install on the a particular machine. Is there a way I can still use the file to install everything BUT these? Something like

pip install -r requirements.txt --except=pytorch,torchvision

I don't see anything like this in the pip options but maybe there's another way.

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Peter
  • 12,274
  • 9
  • 71
  • 86
  • Does this answer your question? [pip install -r all dependencies from the file except one](https://stackoverflow.com/questions/57194887/pip-install-r-all-dependencies-from-the-file-except-one) – Bernhard Stadler Jan 12 '23 at 19:33

2 Answers2

4

There is no way. You have to somehow process the list and exclude packages before passing them to pip. Something like

pip install `grep -v 'pytorch\|torchvision' requirements.txt`
phd
  • 82,685
  • 13
  • 120
  • 165
  • 1
    Just to embellish this answer with an explanation, the -v argument ignores all lines including pytorch and or torchvision – Akanni Dec 27 '20 at 13:40
1

If you are working in Bash, it might be a better idea to use process substitution:

pip install -r <(grep -vE '\<pytorch\>|\<torchvision\>' requirements.txt)

This way, you don't have to worry about comments etc. Adding the word boundaries \< and \> avoids accidentally excluding packages that contain the name of one of the unwanted packages in their names.

Bernhard Stadler
  • 1,725
  • 14
  • 24