Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does pip uninstall required packages?

Tags:

python

pip

pip seems to wantonly uninstall packages that are required! If a package explicitly declares a particular version of a package, it seems that pip ought to fail to uninstall that package, but it doesn't. Consider:

$ pip list | grep bar
bar           1.0    
$ cat setup.py 

from setuptools import setup, find_packages

def do_setup():
    setup(
        name='foo',
        description='the foo package',
        license='MIT',
        version='1.0',
        install_requires=[
            'bar==1.0',
        ],
    )

if __name__ == "__main__":
    do_setup()
$ pip install .
Processing /Users/williamp/examples/pip/foo
  Requirement already satisfied (use --upgrade to upgrade): foo==1.0 from file:///Users/williamp/examples/pip/foo in /Users/williamp/tmp/virt/lib/python2.7/site-packages
Requirement already satisfied: bar==1.0 in /Users/williamp/tmp/virt/lib/python2.7/site-packages (from foo==1.0)
$ cd ../bar
$ pip install dist/bar-1.1.tar.gz 
Processing ./dist/bar-1.1.tar.gz
Building wheels for collected packages: bar
  Running setup.py bdist_wheel for bar ... done
  Stored in directory: /Users/williamp/Library/Caches/pip/wheels/bf/d3/68/6016190bb2084f62ba1107c63bea948f4cfbb2c129fa0cb102
Successfully built bar
Installing collected packages: bar
  Found existing installation: bar 1.0
    Uninstalling bar-1.0:
      Successfully uninstalled bar-1.0
Successfully installed bar-1.1

It seems that I wind up in a situation where package foo is installed with an explicit dependency on bar == 1.0, but pip has uninstalled bar 1.0 and the system is now in an unstable state. Is there some simple config option I can pass to pip to tell it to not do this?

like image 795
William Pursell Avatar asked Nov 28 '25 12:11

William Pursell


1 Answers

No, but you can check for this manually by running pip check:

$ pip check
No broken requirements found.
$ pip uninstall pytz
Uninstalling pytz-2017.3:
  ...
Proceed (y/n)? y
  Successfully uninstalled pytz-2017.3
$ pip check
Django 2.0 requires pytz, which is not installed.

Dependency tracking has been a major issue with pip for a while now. It'll get fixed eventually, I hope.

like image 163
Blender Avatar answered Nov 30 '25 01:11

Blender