You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Show notification when deactivate command is run in terminal #22121
Deactivate command is broken for venv when in pythonTerminalEnvVarActivation experiment #22037:
Investigate whether it's possible to detect when a "deactivate" command is run and show a notification guiding users to the workaround for their shell: #22037 (comment).
microsoft/vscode#145234 could be the long term solution, we can either use it to reliably detect when a deactivate command is run with its output or we can use it to apply the workaround itself and remove the notification.
We should at least be able to remove part of the workaround which initializes the variables: #22037 (comment).
Deactivating virtual environments may not work by default due to a technical limitation in our activation approach, but it can be resolved with a few simple steps.
[See Instructions] [Don't Show Again]
"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.
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.
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.
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.
changed the title [-]Spike: Show notification when deactivate command is run in terminal[/-][+]Show notification when deactivate command is run in terminal[/+]on Oct 21, 2023
To fix this the following script needs to be added to any of the init scripts for the shell you're using:
Thank you! This finally worked to restore the excellent "deactivate" option.
Couldn't the new approach to activate terminals be optional?
For many reasons, I often use different environments, and having the possibility to activate/deactivate them at will was an amazing option in VSCode. It used to allow, for example, the development of certain projects under different sets of dependencies, e.g. to test tools under development.
All these things should be possible with the new approach as well. If you need more guidance, please create a new issue using Python: Report Issue command and we can help you do that for your case.
Activity
karrtikr commentedon Oct 1, 2023
microsoft/vscode#145234 could be the long term solution, we can either use it to reliably detect when a
deactivatecommand is run with its output or we can use it to apply the workaround itself and remove the notification.We should at least be able to remove part of the workaround which initializes the variables: #22037 (comment).
karrtikr commentedon Oct 1, 2023
Notification:
karrtikr commentedon Oct 2, 2023
Add wiki for it: https://aka.ms/AAmx2ft
karrtikr commentedon Oct 2, 2023
"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-pythondirectory.Edit your
~/.bashrcfile to add the following, you can runcode ~/.bashrcin bash to open the file in VS Code: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-pythondirectory.Edit your PowerShell profile to add the following, you can run
code $Profilein pwsh to open (or if need be, create) the file in VS Code: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-pythondirectory.Edit your
~/.zshrcfile to add the following, you can runcode ~/.zshrcin zsh to open the file in VS Code: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-pythondirectory.Edit your
config.fishfile to add the following, you can runcode $__fish_config_dir/config.fishin fish to open the file in VS Code: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-pythondirectory.Edit your
~/.cshrcfile to add the following, you can runcode ~/.cshrcin csh to open the file in VS Code:where
<path_to_dir>is the directory where you downloaded the deactivate script.For example, if path to directory was
~/.vscode-python:Other shells
Powershellcategory.Bashcategory.Make sure to restart the shell after editing your script, reloading VS Code will not work to apply this change.
Why it works:
In the new approach, we do not run
<venv>/<bin>/activatescript which traditionally registers thedeactivateshell hook. Hence we need to add it manually to shell initialization script (~/.bashrcfor example) which is executed automatically when a terminal starts.Alternative solution:
Turn off auto-activation: Set
"python.terminal.activateEnvironment": falseand reopen the shells.Show notification when deactivate command is run in terminal (#22133)
karrtikr commentedon Oct 5, 2023
Output for
Pythonin theOutputpanel (View→Output, change the drop-down the upper-right of theOutputpanel toPython)karrtikr commentedon Oct 5, 2023
Bugbash feedback:
~/.bashrcfor example) and inserts thesource ~/deactivatewithout saving the file.bashrcdirectly to put the contents as that is more susceptible to errors which we can't fix laterkarrtikr commentedon Oct 14, 2023
Brett Cannon (@brettcannon) Your log seems to contain a line:
indicating
"python.terminal.activateEnvironment"setting was set tofalsefor your workspace, which is why activation didn't work. 🙂karrtikr commentedon Oct 18, 2023
TODO: Add a special variable to indicate whether shell integration is active.
[-]Spike: Show notification when deactivate command is run in terminal[/-][+]Show notification when deactivate command is run in terminal[/+]vv-monsalve commentedon Oct 31, 2023
Thank you! This finally worked to restore the excellent "deactivate" option.
Couldn't the new approach to activate terminals be optional?
For many reasons, I often use different environments, and having the possibility to activate/deactivate them at will was an amazing option in VSCode. It used to allow, for example, the development of certain projects under different sets of dependencies, e.g. to test tools under development.
karrtikr commentedon Oct 31, 2023
All these things should be possible with the new approach as well. If you need more guidance, please create a new issue using
Python: Report Issuecommand and we can help you do that for your case.vv-monsalve commentedon Nov 1, 2023
Thank you. I'll keep using it with the added
deactivatescript and see from there. I'll create a new issue if needed.karrtikr commentedon Nov 8, 2023
#22448 solves this without the need for a notification or altering
.bashrc.