How to leave/exit/deactivate a Python virtualenv

Published on Aug. 22, 2023, 12:15 p.m.

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

Depending on your operating system and how you set up the virtual environment, the command to deactivate may vary slightly. Here are some examples:

  • On Unix or Linux, simply type deactivate:
deactivate
  • On Windows, use the Scripts folder to run the deactivate.bat script:
Scripts\deactivate.bat
  • If you are using conda, you will need to use the conda deactivate command:
conda deactivate

It’s important to note that once you deactivate a virtualenv, any packages you installed while in that environment will no longer be available. Therefore, if you need to use that environment again in the future, you will need to activate it again and reinstall the packages.