Skip to content

Fixing "deactivate" command for virtual environments

Kartik Raj edited this page Oct 4, 2023 · 17 revisions

"deactivate" not working by default is a limitation of our new approach to activate terminals. To fix this add the following script to any of the init scripts for the shell you're using:

Bash


  • Add one of the following to ~/.bashrc file. Run code ~/.bashrc in bash to open the file in VS Code:
    • Download deactivate script and add the following:

      source <path_to_dir>/deactivate
    • Or add contents of deactivate directly.


Powershell


  • Add one of the following to your PowerShell profile. Run code $Profile in pwsh to open the file in VS Code:

Zsh


  • Add one of the following to ~/.zshrc file. Run code ~/.zshrc in bash to open the file in VS Code:
    • Download deactivate script and add the following:

      source <path_to_dir>/deactivate
    • Or add contents of deactivate directly.


Fish


  • Add one of the following to your config.fish. Run code $__fish_config_dir/config.fish in fish to open the file in VS Code:

Csh


-Add one of the following to your ~/.cshrc. Run code ~/.cshrc in fish to open the file in VS Code:


Other shells


  • Use default script for the OS:
    • If on Windows, use the script under Powershell category.
    • Otherwise, use the script under Bash category.
  • Add the script at the end of corresponding initialization script for your shell.

Why it works:

In the new approach, we do not run <venv>/<bin>/activate script which traditionally registers the deactivate shell hook. Hence we need to add it manually to shell initialization script (~/.bashrc for example) which is executed automatically when a terminal starts.

Alternative solution:

Turn off auto-activation: Set "python.terminal.activateEnvironment": false and reopen the shells.

Clone this wiki locally