How to install the newest version of a package with a specific tag?

Viewed 61

I'm trying to specify in the requirements.txt file that I want to install the newest version of a package, but only with a specific tag (the string after the + symbol, which is called a local version label in PEP440).

Specifically, the torch package provides two versions, one for GPU+CPU and one for just the CPU. You can download the CPU-only version by appending the +cpu string to a full version string, e.g. torch==1.10.0+cpu (though you also need to use --find-links option).

I've read the entire PEP440 and PEP508, and unless I misunderstood them, there is no way to ask for a specific tag without providing a specific version at the same time. I've tried to cheat my way with strings like torch==1.*+cpu, torch>=1.0+cpu or torch==+cpu but neither worked (and as far as I understand, PEP440 explicitly says they shouldn't work).

Is there a way to achieve what I'm trying to do? How can I automatically download the newest torch CPU-only version?


One somewhat promising solution I found is to use --find-links option and require torch without any version specifiers. In my empirical tests, the +cpu version was always the one that got downloaded. However, I couldn't find any information in PEP440 regarding the relative ordering (besides the example) between versions 1.10.0 and 1.10.0+cpu. I assumed my empirical tests were not deterministic and I discarded this solution.

0 Answers
Related