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
experiment 'pythonTerminalEnvVarActivation' not working because shell integration is not working #22418
The experiment 'pythonTerminalEnvVarActivation' does not work when "terminal.integrated.shellIntegration.enabled": true and the user's PowerShell ExecutionPolicy is Restricted. This experiment was originally touted as a way to get around the conda init powershell issues which required users to elevate their ExecutionPolicy, but it seems to be only a partial fix.
Current solution: set "terminal.integrated.shellIntegration.enabled": false. The display does not show currently activate environment etc. but everything seems to working correctly.
Note: elevating the user's ExecutionPolicy is not a viable solution as organizations may not allow that.
Extension version: 2023.20.0
VS Code version: Code 1.84.0 (d037ac076cee195194f93ce6fe2bdfe2969cc82d, 2023-11-01T11:29:04.398Z)
OS version: Windows_NT x64 10.0.19044
Modes:
It seems conda executable is not on PATH which is leading to this behavior:
2023-11-07 10:20:30.572 [debug] Setting environment variable CONDA_EXE in collection to C:\LocalPrograms\g2encmck\miniconda3\Scripts\conda.exe
Can you print PATH when it fails and see if it contains C:\LocalPrograms\g2encmck\miniconda3\Scripts? Also, compare it to PATH when it succeeds and see if it contains it.
When it is working ("terminal.integrated.shellIntegration.enabled": false) PATH contains the following Conda-related paths (where stratsamp the Conda environment I am using in the project)
as well as the variable CONDA_EXE which is C:\LocalPrograms\g2encmck\miniconda3\Scripts\conda.exe.
When it is not working ("terminal.integrated.shellIntegration.enabled": true) there are no Conda-related paths in PATH, but the CONDA_EXE variable does exist and has the same value C:\LocalPrograms\g2encmck\miniconda3\Scripts\conda.exe.
I do not have CONDA_EXE defined in my system or user environment variables, so presumably VSCode is generating that from the "python.condaPath" setting.
I see, let me look deeper into it. Meanwhile, is changing the policy even for just the current user not an option?
No it is not, the organization sets this policy and will not change it. Would VSCode be able to pass -ExecutionPolicy ByPass witu the environment injection script? That might work.
Issue arises from the fact that we're not able to reliably figure out whether Shell integration is working or not. In this case, it boils down to reliably finding out whether Powershell execution is restricted, can you run the following command on your system:
Get-ExecutionPolicy
I'm expecting it would result in Restricted, which I'm hoping is something we could check to figure out whether shell integration is working.
Yes, PowerShell ExecutionPolicy is Restricted in this case which is why the shell integration call fails (see top right of first image and reference to shellIntegration.ps1). I am curious if modifying the shell integration command to include -ExecutionPolicy ByPass would generally resolve the issue, but perhaps that is outside of the Python extension scope.
if modifying the shell integration command to include -ExecutionPolicy ByPass would generally resolve the issue, but perhaps that is outside of the Python extension scope.
Yes, that's not something we currently control, Python extension does not have it's own profile, we just use the selected one.
I've created #22439 to make sure we solve your issue. Where we will more generally work on a way to figure out whether shell integration is working, rather than just checking the powershell execution policy.
Activity
karrtikr commentedon Nov 6, 2023
Can you please elaborate on what you see as screenshots which leads you to conclude that it is not working?
Also, try the pre-release version of the Python extension:
karrtikr commentedon Nov 6, 2023
If none of these work, we would further need the debug logs to diagnose the issue:
Developer: Set log levelcommandTraceDeveloper: Reload WindowcommandOutput for
Pythonin theOutputpanel (View→Output, change the drop-down the upper-right of theOutputpanel toPython)mkoohafkan commentedon Nov 7, 2023
Here are screenshots:
Not working

Working

No change when switching to pre-release version.
Log:
karrtikr commentedon Nov 7, 2023
I see, let me look deeper into it. Meanwhile, is changing the policy even for just the current user not an option?
#2559 (comment)
Also, I assume
conda initis not run for your Powershell. If it was run previously, one can revert it using,karrtikr commentedon Nov 7, 2023
It seems conda executable is not on
PATHwhich is leading to this behavior:Can you print
PATHwhen it fails and see if it containsC:\LocalPrograms\g2encmck\miniconda3\Scripts? Also, compare it toPATHwhen it succeeds and see if it contains it.mkoohafkan commentedon Nov 7, 2023
When it is working (
"terminal.integrated.shellIntegration.enabled": false)PATHcontains the following Conda-related paths (wherestratsampthe Conda environment I am using in the project)as well as the variable
CONDA_EXEwhich isC:\LocalPrograms\g2encmck\miniconda3\Scripts\conda.exe.When it is not working (
"terminal.integrated.shellIntegration.enabled": true) there are no Conda-related paths inPATH, but theCONDA_EXEvariable does exist and has the same valueC:\LocalPrograms\g2encmck\miniconda3\Scripts\conda.exe.I do not have
CONDA_EXEdefined in my system or user environment variables, so presumably VSCode is generating that from the"python.condaPath"setting.mkoohafkan commentedon Nov 8, 2023
No it is not, the organization sets this policy and will not change it. Would VSCode be able to pass
-ExecutionPolicy ByPasswitu the environment injection script? That might work.karrtikr commentedon Nov 8, 2023
Issue arises from the fact that we're not able to reliably figure out whether Shell integration is working or not. In this case, it boils down to reliably finding out whether Powershell execution is restricted, can you run the following command on your system:
I'm expecting it would result in
Restricted, which I'm hoping is something we could check to figure out whether shell integration is working.mkoohafkan commentedon Nov 8, 2023
Yes, PowerShell ExecutionPolicy is
Restrictedin this case which is why the shell integration call fails (see top right of first image and reference toshellIntegration.ps1). I am curious if modifying the shell integration command to include-ExecutionPolicy ByPasswould generally resolve the issue, but perhaps that is outside of the Python extension scope.karrtikr commentedon Nov 8, 2023
Yes, that's not something we currently control, Python extension does not have it's own profile, we just use the selected one.
I've created #22439 to make sure we solve your issue. Where we will more generally work on a way to figure out whether shell integration is working, rather than just checking the powershell execution policy.
karrtikr commentedon Nov 8, 2023
Btw, the issue is your case was here:
vscode-python/src/client/terminals/envCollectionActivation/service.ts
Lines 343 to 356 in cc38abb
isActivewas returningtruewhen shell integration was failing, leading to us not being able to apply the envs.