-
Couldn't load subscription status.
- Fork 1.3k
Fixing "deactivate" command for virtual environments
"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
~/.bashrcfile. Runcode ~/.bashrcin bash to open the file in VS Code:-
Download
deactivatescript and add the following:source <path_to_dir>/deactivate
-
Or add contents of
deactivatedirectly.
-
Powershell
- Add one of the following to your PowerShell profile. Run
code $Profilein pwsh to open the file in VS Code:-
Download
deactivate.ps1script and add the following:& "<path_to_dir>/deactivate.ps1"
-
Or add contents of
deactivate.ps1directly.
-
Zsh
- Add one of the following to
~/.zshrcfile. Runcode ~/.zshrcin bash to open the file in VS Code:-
Download
deactivatescript and add the following:source <path_to_dir>/deactivate
-
Or add contents of
deactivatedirectly.
-
Fish
- Add one of the following to your
config.fish. Runcode $__fish_config_dir/config.fishin fish to open the file in VS Code:-
Download
deactivate.fishscript and add the following:source <path_to_dir>/deactivate.fish
-
Or add contents of
deactivate.fishdirectly.
-
Csh
-Add one of the following to your ~/.cshrc. Run code ~/.cshrc in fish to open the file in VS Code:
-
Download
deactivate.cshscript and add the following:source <path_to_dir>/deactivate.csh
-
Or add contents of
deactivate.cshdirectly.
Other shells
- Use default script for the OS:
- If on Windows, use the script under
Powershellcategory. - Otherwise, use the script under
Bashcategory.
- If on Windows, use the script under
- Add the script at the end of corresponding initialization script for your shell.
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.
Turn off auto-activation: Set "python.terminal.activateEnvironment": false and reopen the shells.