How to leave/exit/deactivate a Python virtualenv

To leave a Python virtual environment, you can use the deactivate command. This will return you to the system's default Python environment.

For example:

$ deactivate

You can also use the exit command to leave the virtual environment, but this will terminate the terminal session.

$ exit

Watch a course Python - The Practical Guide

Alternatively, you can simply close the terminal window to leave the virtual environment.

If you want to reactivate the virtual environment at a later time, you can use the activate script that is located in the bin directory of the virtual environment.

$ source bin/activate

This will activate the virtual environment, and you will see the name of the virtual environment in the command prompt. To confirm that you are in a virtual environment, you can check the value of the VIRTUAL_ENV environment variable.


If the VIRTUAL_ENV variable is set, then you are in a virtual environment.