- 
                Notifications
    
You must be signed in to change notification settings  - Fork 3.2k
 
Description
Description
Summary
Problem
When installing packages from requirements txt pip will ignore environment makers in combination with "extra-index-url".
this requirements.txt ignores OS constraints on indexes even though environment markers are defined in PEP508/PyPa Spec and it seems no exception is made for index elements. There fore i would expect this file to be compliant
--extra-index-url=https://download.pytorch.org/whl/nightly/cpu ; sys_platform  == 'darwin'
--extra-index-url=https://download.pytorch.org/whl/cu129 ; sys_platform  != 'darwin'
torch==2.9.0 ; sys_platform  != 'darwin'
torch ; sys_platform  == 'darwin'
torchvision
torchaudio
intended is on mac to instal the nightly CPU and on everything that is not mac (Linux/windows) the CUDA version of pytorch using the extra index.
what happens instead
-pip will  ignore the markers on the first two lines, but it process the indexes and thus and concatenate the indexes one after another (which makes sense as those are extra indexes)
-pip will obey the markers on the packages (e,g, torch==2.9.0 ; sys_platform  != 'darwin')
pips output when running the first example (e.g. on Macos):
Looking in indexes: https://pypi.org/simple, https://download.pytorch.org/whl/nightly/cpu, https://download.pytorch.org/whl/cu129
Ignoring torch: markers 'sys_platform != "darwin"' don't match your environment
it installs the normal release torch==2.9.0 (not the nightly from pytorch).
is this intended behavior? or a bug?
the documentation (as far as i read it) does not make an exception for environment markers (sys_platform, os_name, etc).
markers work otherwise normally as expected on normal package names.
Expected behavior
No response
pip version
25.3
Python version
3.13, 3.12, 3.10
OS
MacOS, Linux, Windows
How to Reproduce
save this file as requirements.txt
--extra-index-url=https://download.pytorch.org/whl/nightly/cpu ; sys_platform  == 'darwin'
--extra-index-url=https://download.pytorch.org/whl/cu129 ; sys_platform  != 'darwin'
torch==2.9.0 ; sys_platform  != 'darwin'
torch ; sys_platform  == 'darwin'
torchvision
torchaudio
install with pip on macOS.
Output
$ pip install -r requirements.txt
Looking in indexes: https://pypi.org/simple, https://download.pytorch.org/whl/nightly/cpu, https://download.pytorch.org/whl/cu129
Ignoring torch: markers 'sys_platform != "darwin"' don't match your environment
Collecting torch (from -r uvtest.txt (line 4))
Downloading torch-2.9.0-cp313-none-macosx_11_0_arm64.whl.metadata (30 kB)
Collecting torchvision (from -r uvtest.txt (line 5))
Downloading torchvision-0.24.0-cp313-cp313-macosx_12_0_arm64.whl.metadata (5.9 kB)
Collecting torchaudio (from -r uvtest.txt (line 6))
Downloading torchaudio-2.9.0-cp313-cp313-macosx_12_0_arm64.whl.metadata (6.9 kB)
Collecting filelock (from torch->-r uvtest.txt (line 4))
Downloading https://download.pytorch.org/whl/nightly/filelock-3.20.0-py3-none-any.whl.metadata (2.1 kB)
Collecting typing-extensions>=4.10.0 (from torch->-r uvtest.txt (line 4))
Downloading https://download.pytorch.org/whl/typing_extensions-4.15.0-py3-none-any.whl.metadata (3.3 kB)
Collecting setuptools (from torch->-r uvtest.txt (line 4))
Downloading setuptools-80.9.0-py3-none-any.whl.metadata (6.6 kB)
Collecting sympy>=1.13.3 (from torch->-r uvtest.txt (line 4))
Downloading https://download.pytorch.org/whl/sympy-1.14.0-py3-none-any.whl.metadata (12 kB)
Collecting networkx>=2.5.1 (from torch->-r uvtest.txt (line 4))
Downloading https://download.pytorch.org/whl/networkx-3.5-py3-none-any.whl.metadata (6.3 kB)
Collecting jinja2 (from torch->-r uvtest.txt (line 4))
Downloading https://download.pytorch.org/whl/jinja2-3.1.6-py3-none-any.whl.metadata (2.9 kB)
Collecting fsspec>=0.8.5 (from torch->-r uvtest.txt (line 4))
Downloading https://download.pytorch.org/whl/fsspec-2025.9.0-py3-none-any.whl.metadata (10 kB)
Collecting numpy (from torchvision->-r uvtest.txt (line 5))
Downloading https://download.pytorch.org/whl/nightly/numpy-2.3.4-cp313-cp313-macosx_14_0_arm64.whl.metadata (62 kB)
Collecting pillow!=8.3.*,>=5.3.0 (from torchvision->-r uvtest.txt (line 5))
Downloading https://download.pytorch.org/whl/nightly/pillow-12.0.0-cp313-cp313-macosx_11_0_arm64.whl.metadata (8.8 kB)
Collecting mpmath<1.4,>=1.1.0 (from sympy>=1.13.3->torch->-r uvtest.txt (line 4))
Downloading https://download.pytorch.org/whl/mpmath-1.3.0-py3-none-any.whl (536 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 536.2/536.2 kB 6.1 MB/s  0:00:00
Collecting MarkupSafe>=2.0 (from jinja2->torch->-r uvtest.txt (line 4))
Downloading markupsafe-3.0.3-cp313-cp313-macosx_11_0_arm64.whl.metadata (2.7 kB)
Downloading torch-2.9.0-cp313-none-macosx_11_0_arm64.whl (74.5 MB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 74.5/74.5 MB 6.9 MB/s  0:00:10
Downloading torchvision-0.24.0-cp313-cp313-macosx_12_0_arm64.whl (1.9 MB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 1.9/1.9 MB 6.8 MB/s  0:00:00
Downloading torchaudio-2.9.0-cp313-cp313-macosx_12_0_arm64.whl (809 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 809.1/809.1 kB 5.8 MB/s  0:00:00
Downloading https://download.pytorch.org/whl/fsspec-2025.9.0-py3-none-any.whl (199 kB)
Downloading https://download.pytorch.org/whl/networkx-3.5-py3-none-any.whl (2.0 MB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 2.0/2.0 MB 6.4 MB/s  0:00:00
Downloading https://download.pytorch.org/whl/nightly/pillow-12.0.0-cp313-cp313-macosx_11_0_arm64.whl (4.7 MB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 4.7/4.7 MB 7.2 MB/s  0:00:00
Downloading https://download.pytorch.org/whl/sympy-1.14.0-py3-none-any.whl (6.3 MB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 6.3/6.3 MB 7.0 MB/s  0:00:00
Downloading https://download.pytorch.org/whl/typing_extensions-4.15.0-py3-none-any.whl (44 kB)
Downloading https://download.pytorch.org/whl/nightly/filelock-3.20.0-py3-none-any.whl (16 kB)
Downloading https://download.pytorch.org/whl/jinja2-3.1.6-py3-none-any.whl (134 kB)
Downloading markupsafe-3.0.3-cp313-cp313-macosx_11_0_arm64.whl (12 kB)
Downloading https://download.pytorch.org/whl/nightly/numpy-2.3.4-cp313-cp313-macosx_14_0_arm64.whl (5.1 MB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 5.1/5.1 MB 6.7 MB/s  0:00:00
Downloading setuptools-80.9.0-py3-none-any.whl (1.2 MB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 1.2/1.2 MB 6.9 MB/s  0:00:00
Installing collected packages: mpmath, typing-extensions, sympy, setuptools, pillow, numpy, networkx, MarkupSafe, fsspec, filelock, jinja2, torch, torchvision, torchaudio
Successfully installed MarkupSafe-3.0.3 filelock-3.20.0 fsspec-2025.9.0 jinja2-3.1.6 mpmath-1.3.0 networkx-3.5 numpy-2.3.4 pillow-12.0.0 setuptools-80.9.0 sympy-1.14.0 torch-2.9.0 torchaudio-2.9.0 torchvision-0.24.0 typing-extensions-4.15.0
Code of Conduct
- I agree to follow the PSF Code of Conduct.