Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does Pip ignore conflicting dependencies?

If I create a dummy package -- here's /tmp/example_package/setup.py (note the requirements):

from distutils.core import setup

setup(name='my_project',
      description="Just a test project",
      version="1.0",
      py_modules=['sample'],
      install_requires=['requests > 0.12'])

Here's /tmp/example_package/sample.py:

import requests

def get_example():
    return requests.get("http://www.example.com")

Now, I create a virtualenv:

$ virtualenv /tmp/foobar --distribute -p python2.7
Running virtualenv with interpreter /usr/bin/python2.7
New python executable in /tmp/foobar/bin/python2.7
Also creating executable in /tmp/foobar/bin/python
Installing distribute.................................................................................................................................................................................................done.
Installing pip................done.
$ source /tmp/foobar/bin/activate

I create a requirements.pip with conflicting requirements:

# this requires requests > 0.12:
file:///tmp/example_package

# but this conflicts:
requests==0.9.0

Pip happily installs this:

$ pip install -r requirements.pip                                                                                                                                                                       [18:40:10]
Unpacking ./example_package
  Running setup.py egg_info for package from file:///tmp/example_package

Downloading/unpacking requests==0.9.0 (from -r requirements.pip (line 3))
  Downloading requests-0.9.0.tar.gz (55Kb): 55Kb downloaded
  Running setup.py egg_info for package requests

Downloading/unpacking certifi>=0.0.4 (from requests==0.9.0->-r requirements.pip (line 3))
  Downloading certifi-0.0.8.tar.gz (118Kb): 118Kb downloaded
  Running setup.py egg_info for package certifi

Installing collected packages: requests, my-project, certifi
  Running setup.py install for requests

  Running setup.py install for my-project

  Running setup.py install for certifi

Successfully installed requests my-project certifi
Cleaning up...

Why does Pip allow this? My example_package won't work, because its requirements aren't met.

like image 716
Wilfred Hughes Avatar asked Jan 21 '13 18:01

Wilfred Hughes


People also ask

How do you resolve dependency conflicts in pip?

Unfortunately, pip makes no attempt to resolve dependency conflicts. For example, if you install two packages, package A may require a different version of a dependency than package B requires. Pip can install from either Source Distributions (sdist) or Wheel (. whl) files.

Does pip dependency resolution?

Pip does not provide true dependency resolution, but this can be solved by using it in conjunction with a requirements. txt file. Requirements. txt files can be used to make pip resolve dependency conflicts between different packages.

Why pip is not working in Terminal?

One of the most common problems with running Python tools like pip is the “not on PATH” error. This means that Python cannot find the tool you're trying to run in your current directory. In most cases, you'll need to navigate to the directory in which the tool is installed before you can run the command to launch it.

How does pip decide which version to install?

Once pip has a list of compatible distributions, it sorts them by version, chooses the most recent version, and then chooses the "best" distribution for that version. It prefers binary wheels if there are any, and if they are multiple it chooses the one most specific to the install environment.


2 Answers

This is a limitation of Pip. The requirements file trumps the requirements of the packages. See https://github.com/pypa/pip/issues/775#issuecomment-12748095

like image 107
Wilfred Hughes Avatar answered Oct 01 '22 01:10

Wilfred Hughes


Looking at the pip source it seems like it should recursively add all the requirements to one big RequirementSet... and then crash out with a 'Duplicate requirement' exception...

Hmm.. are you sure your setup.py is correct?

Distutils has a requires keyword but not install_requires: http://docs.python.org/2/distutils/setupscript.html#relationships-between-distributions-and-packages

SO answers which reference this:
https://stackoverflow.com/a/10686196/202168
https://stackoverflow.com/a/13468644/202168

like image 33
Anentropic Avatar answered Oct 01 '22 02:10

Anentropic