SebastienTs
(Sébastien Tosi)
January 11, 2024, 1:38pm
1
In a pip_requirements.txt file, is there a way to specify the channel to use for some specific packages to avoid having to call pip twice as below:
pip install -r env_requirements.txt
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118
1 Like
kknechtel
(Karl Knechtel)
January 12, 2024, 4:21am
2
To my understanding, each line of the file is literally just a listing of command-line arguments for an invocation of Pip; so you should be able to just write e.g. torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118
on a line of the file.
1 Like
mondaini
(Matheus Mondaini)
May 16, 2024, 2:30pm
3
Unfortunately, it doesn’t work as expected in most cases (every computer i tried). He’s right about having to call pip twice in this scenario.
sinoroc
(sinoroc)
May 16, 2024, 4:25pm
4
--index-url
is a global option, it must be on its own line and is valid for the whole file: Requirements File Format - pip documentation v24.0
mondaini
(Matheus Mondaini)
May 16, 2024, 6:05pm
5
Yes, it’s nice to mention it too, beacause it’s the reason why he has to call pip twice in this scenario.
mondaini
(Matheus Mondaini)
May 16, 2024, 6:10pm
6
My solution for you to use only one pip command line is as follows:
Keep your original requiments.txt file as it is.
Create another requirements.txt file but with a different name, such as ‘requirements2.txt’.
So, you can call pip once using ‘pip install -r requirements1.txt -r requirements2.txt’
edit: Don’t forget to index the url in a single line in requirements2.txt, before you call the packages.