'pip installable package with alternative index in requirements.txt

Along the lines of pip requirements.txt with alternative index (see also this) I have to install a version of a package that requires passing an --extra-index-url and I want to do this inside requirements.txt. This works if I run pip install -r requirements.txt.

The kicker is that I want my package to be pip installable. I have the requirements.txt of my package inside a directory with the other necessary files like setup.py and the pyproject.toml and whilst I can run the previous command I can't do pip install . to install my package locally from the current directory.

How can I ship a pip installable package with a requirements.txt file that contains an extra index URL?

(If pip doesn't allow this as I suspect, please suggest workarounds!)

Right now I have this in the requirements file (just an excerpt):

seaborn==0.11.2
--extra-index-url https://download.pytorch.org/whl/cu113 
torch==1.10.2+cu113 
pandas==1.1.5
numpy==1.17.4

My specific use case is with PyTorch, which I need to install with the correct CUDA version, so the command to install the relevant packages from PyTorch Start Locally is:

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


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source