How to leave/exit/deactivate a Python virtualenv
To leave a Python virtual environment, you can use the deactivate command.
To leave a Python virtual environment, you can use the deactivate shell function. This will return you to the system's default Python environment.
For example:
Leave a Python virtual environment using the deactivate command
$ deactivate
<div class="alert alert-info flex not-prose">![]()
<span class="hidden md:block">Watch a video course</span>Python - The Practical Guide</div>
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.
Reactivate a Python virtual environment using the activate script
$ source myenv/bin/activateReplace myenv with the name of your virtual environment folder.
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.
Confirm that you are in a virtual environment
$ echo $VIRTUAL_ENVIf the VIRTUAL_ENV variable is set, then you are in a virtual environment.