-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Fixing "deactivate" command for virtual environments
"deactivate" not working by default is a limitation of our new approach to activate terminals. To fix this the following script needs to be added to any of the init scripts for the shell you're using:
Tip: Clicking the "Edit <script>"
button on the notification automatically does this editing for you.
Bash
-
Download the deactivate script into say,
~/.vscode-python
directory. -
Edit your
~/.bashrc
file to add the following, you can runcode ~/.bashrc
in bash to open the file in VS Code:# >>> VSCode venv deactivate hook >>> source <path_to_dir>/deactivate # <<< VSCode venv deactivate hook <<<
where
<path_to_dir>
is the directory where you downloaded the deactivate script. -
For example, if path to directory was
~/.vscode-python
:
Powershell
-
Download the deactivate.ps1 script into say,
~/.vscode-python
directory. -
Edit your PowerShell profile to add the following, you can run
code $Profile
in pwsh to open (or if need be, create) the file in VS Code:# >>> VSCode venv deactivate hook >>> & "<path_to_dir>/deactivate.ps1" # <<< VSCode venv deactivate hook <<<
where
<path_to_dir>
is the directory where you downloaded the deactivate script. -
For example, if path to directory was
~/.vscode-python
:
Zsh
-
Download the deactivate script into say,
~/.vscode-python
directory. -
Edit your
~/.zshrc
file to add the following, you can runcode ~/.zshrc
in zsh to open the file in VS Code:# >>> VSCode venv deactivate hook >>> source <path_to_dir>/deactivate # <<< VSCode venv deactivate hook <<<
where
<path_to_dir>
is the directory where you downloaded the deactivate script. -
For example, if path to directory was
~/.vscode-python
:
Fish
-
Download the deactivate.fish script into say,
~/.vscode-python
directory. -
Edit your
config.fish
file to add the following, you can runcode $__fish_config_dir/config.fish
in fish to open the file in VS Code:# >>> VSCode venv deactivate hook >>> source <path_to_dir>/deactivate.fish # <<< VSCode venv deactivate hook <<<
where
<path_to_dir>
is the directory where you downloaded the deactivate script. -
For example, if path to directory was
~/.vscode-python
:
Csh
-
Download the deactivate.csh script into say,
~/.vscode-python
directory. -
Edit your
~/.cshrc
file to add the following, you can runcode ~/.cshrc
in csh to open the file in VS Code:# >>> VSCode venv deactivate hook >>> source <path_to_dir>/deactivate.csh # <<< VSCode venv deactivate hook <<<
where
<path_to_dir>
is the directory where you downloaded the deactivate script. -
For example, if path to directory was
~/.vscode-python
:
Other shells
- Use default script for the OS:
- If on Windows, use the script under
Powershell
category. - Otherwise, use the script under
Bash
category.
- If on Windows, use the script under
- Add the script at the end of corresponding initialization script for your shell.
Make sure to restart the shell after editing your script, reloading VS Code will not work to apply this change.
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.