Is there a better alternative to pip-autoremove?

I’ve recently been trying to use best practices when installing packages:

  1. Only installing global packages when it makes sense.
  2. Using virtual environments 99% of the time.
  3. Uninstalling packages whenever they are no longer needed.

I find this to work well for me. However, #3 is a pain when uninstalling packages that have a ton of dependencies, like tensorflow. In comes, pip-autoremove to the rescue.

The issue with pip-autoremove is that it removes everything. Here’s a scenario:

  1. I pip install matplotlib because I need to show some plots.
  2. I then realize that maybe seaborn could fit my needs a little better, so I pip install seaborn.
  3. I realize that I was wrong and matplotlib will actually fit my needs just fine so I pip-autoremove seaborn.
  4. Uh, oh! That removed seaborn AND matplotlib!
  5. Now, I have to pip install matplotlib again before I can continue development.

Is there a better solution out there to this specific problem? Or, is this more of me needing to change my philosophy on package management?

>Solution :

I usually recommend using Poetry to handle your virtual environments. Poetry creates a single .venv per project and tracks all your dependencies with two files that can be tracked by git, pyproject.toml and poetry.lock.

When you remove with poetry a dependency (seaborn) that also depends on another installed dependency (matplotlib), poetry will remove all the extra dependencies that seaborn has installed and rollback the matplotlib dependencies to their previously installed version.

Leave a Reply