Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

  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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading