How can I remove unused packages from virtualenv?
Making virtualenvs is relatively cheap. You could just create a new virtualenv whenever you get into this situation and run your pip install again.
Not very elegant, but it gets the job done. Of course you need to be maintaining some requirements file for the pip install and it will go faster if you have some local index or cache for pip.
Virtualenv - Cleaning up unused package installations
A method I use is with my requirements.txt
files. From the root of my Django project, I create a requirements/
directory with the following files in it:
requirements/
base.txt
dev.txt
prod.txt
temp.txt
base.txt
contains packages to be used in all environments such as Django==1.8.6
.
Then dev would include base and other packages, and might look like:
-r base.txt
coverage==4.0.2
Then temp.txt
includes dev.txt
and contains packages I'm not sure I'll use permanently:
-r dev.txt
temp_package==1.0
git+https://github.com/django/django.git#1014ba026e879e56e0f265a8d9f54e6f39843348
Then I can blow away the entire virtualenv and reinstall it from the appropriate requirements file like so:
pip install -r requirements/dev.txt
Or, to include the temp_package I'm testing:
pip install -r requirements/temp.txt
That's just how I do it, and it helps keep my sandbox separate from the finished product.
How can I 'clean up' a virtualenv?
This answer may be just what you need.
You can install and use the pip-autoremove utility to remove a package
plus unused dependencies.# install pip-autoremove
pip install pip-autoremove
# remove "somepackage" plus its dependencies:
pip-autoremove somepackage -y
What is the easiest way to remove all packages installed by pip?
I've found this snippet as an alternative solution. It's a more graceful removal of libraries than remaking the virtualenv:
pip freeze | xargs pip uninstall -y
In case you have packages installed via VCS, you need to exclude those lines and remove the packages manually (elevated from the comments below):
pip freeze | grep -v "^-e" | xargs pip uninstall -y
Related Topics
How to Remove a Pandas Dataframe from Another Dataframe
Pandas - How to Compare 2 CSV Files and Output Changes
Sklearn: Typeerror: Fit() Missing 1 Required Positional Argument: 'X"
Finding the Value of the Min and Max Pixel
Replace Empty Strings With None/Null Values in Dataframe
Possible to Get User Input Without Inserting a New Line
Python: How to Match Nested Parentheses With Regex
How to Center a Window on the Screen in Tkinter
How to Download Outlook Attachment from Python Script
Reading Contents of a Gzip File from a Aws S3 in Python
How to Install Pypdf2 Module Using Windows
Pandas Dataframe Check If Column Value Exists in a Group of Columns
How to Connect to a Remote Windows Machine to Execute Commands Using Python
How to Convert Signed to Unsigned Integer in Python
Splitting Timestamp Column into Separate Date and Time Columns
Pythone :How to Use Dataframe Output in Email Body as Text
How to Write a Lambda Function That Is Conditional on Two Variables (Columns) in Python