pypa / pipenv

Python Development Workflow for Humans.
https://pipenv.pypa.io
MIT License
24.88k stars 1.87k forks source link

Feature Idea: Manage Environments / Cleanup Old Environments #4611

Open internetofjames opened 3 years ago

internetofjames commented 3 years ago

Background

I use pipenv for all my python projects, both personal, and at work. Recently, I was running low on storage on my machine, and realized I had many pipenv environments taking up space that could be easily reclaimed. Obviously, it's super easy to delete an environment and all of it's packages from your machine by navigating to the project and running pipenv --rm. However, that only works if the project is still on your machine and has not been moved to a new location. I had several environments that either no longer referenced a project on my computer, or were duplicates because I reorganized where I stored my projects on my machine.

The former is easy, just navigate to ~/.local/share/virtualenvs (I'm on MacOS) and delete the directories that begin with the projects that no longer exist on my computer. But what about the duplicated environments? I suppose it might be possible to reverse engineer the hash and figure out the path the environment was referencing, but I am wondering if pipenv can be enhanced to manage the environments it has created on a machine, much like how Anaconda does.

Proposal

CLI functionality for pipenv (perhaps something like pipenv envs?) that opens up an avenue of commands for managing environments created by pipenv on your machine. From this command, you could do things like list all of your environments, observing the path to the project that the environment references, a subcommand that removes all the files and packages of an environment that no longer references a project on your machine, and more!

matteius commented 2 years ago

I tend to just manage the virtualenvs that are created using virtualenvwrapper or as you mentioned using pipenv --rm but if I moved the directory I can see the generated appended id value with a dash in the virtualenv name and remove them with rmvirtualenv is part of the existing python tooling ecosystem. This position is maybe contrary to some things in the pipenv docs like You no longer need to use pip and virtualenv separately. They work together. which is accurate, but as you describe can create cruft depending on what the user chooses to do. I think one challenge here is that AFAIK pipenv does not currently track some kind of global state about its usage and the environments it has created, or if there is a desire to do so. I will classify this issue as a feature request for the time being.