Including channels in a pip_requirements.txt file

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

1 Like

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 on a line of the file.

1 Like

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.

--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

Yes, it’s nice to mention it too, beacause it’s the reason why he has to call pip twice in this scenario.

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.