pypa / pip

The Python package installer
https://pip.pypa.io/
MIT License
9.5k stars 3.01k forks source link

No matching distribution found when same package is listed with different environment markers #6084

Open AndreyMZ opened 5 years ago

AndreyMZ commented 5 years ago

Environment

Details: https://github.com/docker-library/python/blob/39c500cc8aefcb67a76d518d789441ef85fc771f/3.7/stretch/Dockerfile

Description

pip does not properly work when the same package is listed in a requirements file multiple times with different environment markers.

How to Reproduce

  1. Create file requirements.txt:

    mysqlclient ; sys_platform == 'linux'
    mysqlclient ; sys_platform == 'win32' --only-binary=mysqlclient
  2. Create file Dockerfile:

    FROM python
    COPY ./requirements.txt ./
    RUN pip install -r requirements.txt
  3. Build docker image:

    docker build .

Output (actual behaviour)

C:\bug>docker build .
...
Step 3/3 : RUN pip install -r requirements.txt
 ---> Running in 8f67f72f26d0
Ignoring mysqlclient: markers 'sys_platform == "win32"' don't match your environment
Collecting mysqlclient (from -r requirements.txt (line 1))
  Could not find a version that satisfies the requirement mysqlclient (from -r requirements.txt (line 1)) (from versions: )
No matching distribution found for mysqlclient (from -r requirements.txt (line 1))
The command '/bin/sh -c pip install -r requirements.txt' returned a non-zero code: 1

Expected behavior

Package mysqlclient is successfully installed.

chrahunt commented 5 years ago

The cause appears to be here, where we accumulate options that may be specified multiple times from the requirements.

This is probably also related to #5795.