1

I have following install comand for a package:

pip3 install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu116

and would need to add this to my requirements.txt file. I have done it by adding this to the end of the file:

-i https://download.pytorch.org/whl/cu116
torch
torchvision 
torchaudio

after all the other requirements. I do not have the means to test it right now, and would need to know if I have done it correctly as I never did it before.

Is this the proper way of adding it to the requirements.txt file?

If yes, adding other packages after these, for example numpy, will it be affected by the url? do I have to sort of "clear" the url, or is it simply added to the list of urls it searches in?

Any help appreciated

sharkyenergy
  • 3,842
  • 10
  • 46
  • 97
  • without knowing, my guess is it just adds the url to places pip can search for packages, I'm sure you could find that out in the docs somewhere https://pip.pypa.io/en/stable/reference/installation-report/ – Matthias Sep 01 '22 at 11:03
  • interstingly enough, I did try to do a `pip install -r requirements.txt` with your code there, and it DOES fail. Due to some package dependencies.. the -i part of it does work though. – Matthias Sep 01 '22 at 11:09
  • might have to use something more recent than cu116 perhaps – Matthias Sep 01 '22 at 11:10
  • Does this answer your question? [pip requirements.txt with alternative index](https://stackoverflow.com/questions/2477117/pip-requirements-txt-with-alternative-index) – Matthias Sep 01 '22 at 11:11
  • 1
    @Matthias yes, i googled, thats how i came up with the post in the first place. but since i cannot test it, I was searching for an answer from somebody with more experience. interenstigly it fails, that is not what I hoped. without the requirements, so running the install from the first line, it installs just fine, using cu116. the link you posted, basically says the same as my post, only difference that it works for him and not here apparently... – sharkyenergy Sep 01 '22 at 11:23
  • wow you are right, first line installs fine, the requirements.txt one has some problems resolving the dependencies or something – Matthias Sep 01 '22 at 13:10
  • after I run the first line, and then uninstall with pip, then the requirements file does work, because pip uninstall doesn't uninstall the dependencies. But not in a fresh virtual environment. – Matthias Sep 01 '22 at 13:14

1 Answers1

9

Found the solution, the command you used and the requirements.txt file were NOT in fact the same. It works with a requirements.txt like this

--extra-index-url https://download.pytorch.org/whl/cu116
torch
torchvision 
torchaudio

Turns out -i is not the same as --extra-index-url.

Docs: https://pip.pypa.io/en/stable/reference/requirements-file-format/

Matthias
  • 3,160
  • 2
  • 24
  • 38