3

is there anyway to use pip to see who needs a module BEFORE uninstall? how?

here's why i'm asking:

In RPM package land:

  • each package lists it's own software deps
  • when you go to do a yum remove NAME yum says "PACKAGE_A, PACKAGE_B, ... each depend on NAME" and then yum will bring up an interactive prompt asking "do you want to remove NAME and PACKAGE_A, PACKAGE_B, ..., yes or no?"
  • yum has told me that doing a yum remove NAME would break other things... and so i say "no" and reconsider (or say yes because i want PACKAGE_A, PACKAGE_B, ..., removed)

In PIP package land:

  • each package lists it's own software deps
  • when you go to do a pip uninstall botocore pip says "do you want to remove ${list_of_files_for_botocore_package}, yes or no?"
  • you say yes because you want to remove botocore
  • then you are afraid of breaking stuff so you do
  • pip check
  • then you see "boto3 ... requires botocore, which is not installed"
  • pip uninstall has now left one or more modules in a broken state
    • even though pip knew ahead of time that boto3 required botocore...
    • pip could have warned me or said something or offered to remove boto3 like yum did

i guess i could write some python code to construct a graph... then figure out who needs botocore by looking at the graph... but i'm wondering... does pip already have such a feature already? seems like the default behavior is not that good (it should at least print a message).

Trevor Boyd Smith
  • 18,164
  • 32
  • 127
  • 177
  • 3
    As far as I know there is no such thing in _pip_, but tools such as [_pipdeptree_](https://pypi.org/project/pipdeptree/) or [_deptree_](https://pypi.org/project/deptree/) can help. – sinoroc Dec 17 '19 at 20:53
  • @sinoroc i'm just surprised at the default behavior causing one or more broken state. but maybe the solution is to use your workaround and always check with `pipdeptree -r`. – Trevor Boyd Smith Dec 17 '19 at 20:55
  • https://stackoverflow.com/search?q=%5Bpip%5D+reverse+dependencies – phd Dec 17 '19 at 20:58
  • All answers in the search are about **reverse dependencies**. – phd Dec 17 '19 at 21:19
  • 1
    @phd don't you think: https://stackoverflow.com/q/9232568/52074 is a better duplicate (it has 147 votes and IMO provides the pipdeptree solution... which is much better... the one you linked to... is not nearly as high quality IMO). also question 9232568 is from a year earlier. – Trevor Boyd Smith Dec 17 '19 at 21:32
  • Good enough.... – phd Dec 17 '19 at 21:34
  • @trevor True. Maybe some other tools (layers above _pip_) are better at keeping the user safe from such broken states: [dephell](https://pypi.org/project/dephell/), [poetry](https://pypi.org/project/poetry/), [pipenv](https://pypi.org/project/pipenv/) come to mind. But really -tools or not- in the _pip_-world the key is too keep an accurate list of dependencies somewhere, be it `requirements.txt`, `setup.py`, `setup.cfg`, `pyproject.toml`, `Pipfile` or anything of the sort so that the info doesn't get lost and environments can be recreated quickly without sweat no matter how broken things are. – sinoroc Dec 18 '19 at 11:15

2 Answers2

2

in a nutshell: no

  • pip does not look like it has a reverse dependency checker out of the box.
  • The pip roadmap doesn't look like it will change the uninstall behavior any time soon.
  • so overall the answer is: no

workaround: you have to use a third-party solution like pipdeptree or pipdep

Make sure before calling pip uninstall to always check the reverse software deps to see if you will break anything.

sinoroc
  • 18,409
  • 2
  • 39
  • 70
Trevor Boyd Smith
  • 18,164
  • 32
  • 127
  • 177
-2

What you want is pipenv. Pipenv takes care of installing your packages and setting up your virtual environment in a few easy steps. To see what uses what when you install packages with pipenv, run the command in your terminal

pipenv graph

and you should get a tree list of all dependencies

maestro.inc
  • 796
  • 1
  • 6
  • 13
  • As far as I know, `pipenv graph` uses _pipdeptree_ under the hood. But on the other hand, does `pipenv uninstall` somehow warns if the project about to being uninstalled is a dependency of other currently installed projects and thus that an issue might arise? Which in a sense would provide a solution for the issue that initiated the original question. – sinoroc Dec 17 '19 at 22:41
  • No, `pipenv uninstall` does not warn you if it a dependency or not – maestro.inc Dec 17 '19 at 23:20