Deactivate a Python virtual environment
Leave an activated Python environment, reactivate it on your platform, and check which interpreter a terminal or process is actually using.
Run deactivate in the shell where you activated the environment:
deactivate
This restores the shell environment saved by the activation script, including its previous PATH. It does not delete the virtual environment or stop processes already using its interpreter. The restored Python may be a system installation, a version-manager selection, or another previously configured interpreter.
Other ways to leave the shell session
Closing that terminal ends its shell session. A fresh terminal generally starts without that activation, but an IDE, shell startup file, or inherited environment can activate it again. A new tab is therefore not proof that you are outside the environment.
Reactivate it later
For a virtual environment directory named venv:
# Bash or zsh on Linux/macOS
source venv/bin/activate
# Windows PowerShell
.\venv\Scripts\Activate.ps1
:: Windows Command Prompt
venv\Scripts\activate.bat
Use the script for your shell. Activation changes how commands are resolved; you can also run the environment's Python executable by its full path without activating anything.
FAQ
Why is deactivate unavailable? The current shell may never have run an activation script, or it may use a different environment manager. A virtual-environment interpreter can still be running without an activation command. Inspect it with:
python -c "import sys; print(sys.executable); print(sys.prefix != sys.base_prefix)"
For a standard venv, the Boolean identifies whether that interpreter is running in a virtual environment. On Unix, command -v python shows shell resolution; use where.exe python on Windows. A prompt prefix alone is not conclusive.
Does this work for Conda? Use conda deactivate for a Conda environment. Conda's environment stack and commands are separate from venv activation.
Does deactivation remove installed packages? No. The directory and its packages remain available for the next activation.
Contact us
Join the community
to join the community
Try Guance
Start online and pay only for what you use.
Get startedChoose a Guance plan