Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I 'clean up' a virtualenv?

If I want to keep my venv as clean as possible how can I clean up the stuff I don't need? Let me lay out an example...

Say I try a bunch of new modules...

pip install foo
pip install bar
pip install foobar
pip install foobarfoo

and these modules have some requirements of their own, etc. later I decide on which one I want to use, but then I have a huge list of stuff in my requirement.txt and I can't remember what I need and what I don't, what depends on what, etc.

How can I keep it clean and lean?

like image 497
Joff Avatar asked Jan 29 '16 02:01

Joff


People also ask

How do I delete old virtualenv files?

There is no command for deleting your virtual environment. Simply deactivate it and rid your application of its artifacts by recursively removing it. Note that this is the same regardless of what kind of virtual environment you are using.

Where is virtualenv stored?

The traditional location is ~/. virtualenvs. I use a different setup where I have a ~/projects folder which contains the different virtualenvs and contains the python code for different projects. This is nice and easy because you have everything together.

How do you delete a virtual environment on a Mac?

Click on the Parallels icon on the Mac menu bar > select Control Center. Right-click on your virtual machine and select Remove "virtual machine name"... files if you wish to access the files from this virtual machine later. The virtual machine will be removed from the list, but it will remain in its original location.


2 Answers

To uninstall every package (including dependencies) you can freeze the requirements and then pass them to pip uninstall:

pip freeze > to-uninstall.txt
pip uninstall -r to-uninstall.txt
like image 105
Steve Rossiter Avatar answered Sep 21 '22 21:09

Steve Rossiter


The following works for me (can be executed from any Python 3.6 virtualenv):

virtualenv --clear your-env-name

Where your-env-name could be:

  • Path to the virtual environment (relative from current directory or absolute)
  • Or if you use virtualenv-wrapper, just the name of the environment
like image 34
Artur Barseghyan Avatar answered Sep 20 '22 21:09

Artur Barseghyan