How to Uninstall all Packages from Virtualenv Using Pip?

How to Uninstall all Packages from Virtualenv Using Pip?

How to Uninstall all Packages from Virtualenv Using Pip?

Python is flexible and scalable. We can install a lot of Python libraries and use them in our project without writing the code from scratch. That makes our job easy. But, that comes with the cost of managing those libraries in Python.

In this tutorial we are going learn commands to uninstall all packages from virtual environment.

I remember working on one of the projects where I have to set a virtual environment to run the project. It was a Django project.

After creating a virtual environment, I upgrade the Django library to the latest version. It also upgrades the dependent other libraries. And everything started failing.

I wanted to restore all the Python libraries to the previous version. So here are the steps I followed to uninstall Python libraries.

Activate your virtual environment from where you want to delete all the installed libraries. And then follow the below steps.

Take a Backup of Installed Libraries

You can also take the backup of the installed libraries.

pip freeze > backup_requirements.txt

It will save all the installed libraries and their versions in the file backup_requirements.txt. (You can use this file to install Python libraries anytime in future.)

Uninstall all Packages from Virtualenv using Pip Tool

You might have requirement file in your project. Run below command.

pip uninstall -r requirements.txt

It will seek your permission to uninstall each library.

Remove All Python Libraries All At Once

You can also remove all the libraries all at once. Use -y option.

pip uninstall -r requirements.txt -y

You can verify if all the libraires are removed or not using pip command.

pip freeze

It will show all the installed libraries. In our case, it will not show any library installed.

All these commands works on Windows, MacOS and Linux systems.

You learn more about managing Python modules and libraries.

This is all about this tutorial to uninstall all Packages from virtualenv. If you have specific questions or doubt, let me know in the comment, I can help you.

Happy Pythoning!

Leave a Reply

Your email address will not be published. Required fields are marked *