为什么pip卸载所需的包?

时间:2017-12-13 02:40:44

标签: python pip

pip似乎只是大肆卸载所需的软件包!如果一个包明确地声明了一个特定版本的包,那么pip似乎应该无法卸载该包,但事实并非如此。考虑:

$ 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

似乎我最终安装了包foo,并且显式依赖于bar == 1.0,但是pip已经卸载了bar 1.0,系统现在处于不稳定状态。是否有一些简单的配置选项我可以传递给pip告诉它不要这样做?

2 个答案:

答案 0 :(得分:1)

不,但您可以通过运行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.

依赖关系追踪已经a major issue了一段时间。我希望它最终会得到修复。

答案 1 :(得分:0)

Pip有一个标志来安装没有依赖项的库。尝试...

pip install --no-dependencies dist/bar-1.1.tar.gz