Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

This lesson is for members only. Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Destroying Virtual Environments

00:00 Now what do you do once you’re done with the virtual environment, or you want to recreate it from scratch? How do you get rid of them? Because, if you’re working with virtual environments over time, you are going to accumulate a couple of them, if you’re creating one per project, and so what do you do when you want to get rid of these virtual environments to reclaim the space they take up?

00:20 I am going to show you how to do that now. So we’re going to delete an existing virtual environment here… So right now, I am in this test project folder, and I am inside and active virtual environment; so in order to delete this virtual environment, I would first of all deactivate the environment so that we’re back in the global environment, and then all you need to do is delete this venv folder.

00:46 So, what I am going to do here is I am going to delete it using the rm command and you always want to be careful when you are running this command just as a word of warning, because you can easily delete a bunch of stuff that maybe you don’t want to delete.

01:00 So it might be easier for you to actually go into a file manager and just to delete the venv folder there if you absolutely want to make sure nothing can go wrong.

01:11 But I am going to go ahead here and I am just going to delete this folder, and now you can see the project folder is empty or I actually deleted this venv folder, which means now the virtual environment is gone, it doesn’t take up any space anymore and if I wanted to, I could recreate a virtual environment under the same name and then just repopulate again and configure it in the way I want.

01:31 So this is a great way to reset a virtual environment if something went wrong, you just wipe it out completely, delete it and then rebuild it from scratch.

aravind on Sept. 17, 2019

Do you store your actual python files (project) under root of “test-project”? This video doesnt show where to store python source files and relationship to venv.

Dan Bader RP Team on Sept. 17, 2019

Ryan on July 7, 2020

For ubuntu 20.04: A ~/.bash_aliases file is referenced in ~/.bashrc. I had to create this file and save it as an sh file for the aliases to work.

DISTRIB_ID=Ubuntu DISTRIB_RELEASE=20.04

Zarata on Oct. 19, 2020

Can one simultaneously work in multiple, independent, ACTIVE venv’s by opening multiple terminal sessions (is each terminal session completely sandboxed, or would there be behind the scenes linkages?). Just wondering if one has to truly be very careful about deactivating one venv before messing in another.

Zarata on Oct. 19, 2020

Is there anything special one needs do if one exits a terminal session without remembering to deactivate the venv?

Dan Bader RP Team on Oct. 19, 2020

Great questions @Zarata :) I’ll respond inline below:

Can one simultaneously work in multiple, independent, ACTIVE venv’s by opening multiple terminal sessions?

Yes, the active virtual environment is determined by your shell environment variables. So, in practical terms, if you open multiple terminal session you can have a different active Python virtual environment in each of them.

Is there anything special one needs do if one exits a terminal session without remembering to deactivate the venv?

You don’t need to manually deactivate the Python virtual environment when you exit a terminal session, it happens automatically.

Become a Member to join the conversation.