Repository navigation
integreted powershell's PATH env variables contains unexpected '.' #22073
Description
- VS Code Version: 1.82.2 (user setup)
- OS Version: Windows_NT x64 10.0.19045
Steps to Reproduce:
- open the integreted powershell.
- run any command.
This is a very weird issue that integreted powershell doesn't share the same PATH env variables with the outside powershell 7.
I installed anaconda, mainly for python dev.
Debugging python codes with vscode integreted powershell is successful, but when i wanna use the integreted powershell to do other works(e.g. pip install a whl), it always turns out to be "set-Item: Cannot find drive. A drive with the name '.D' does not exist." error.
Last time i saw this kind of error, i found " '.C' does not exist", and i checked the $env:PATH, find a value is written '.C:/(...)', i used set-Item command removed the value and it started to work properly.
But after a rebooting my computer, it turns out to be the same with "Cannot find drive. A drive with the name '.D' does not exist". however, this time i cannot use set-Item to fix it, the error report is the same 'Cannot find drive'. The $env:PATH has a lot of dumplicates since a .D occurred, and I cannot remove the .D line anymore.
This issue is quite similar to microsoft/vscode#74606, but i don't know if they are really the same.
the outside powershell 7's $env:PATH:
C:\Program Files\PowerShell\7;D:\anaconda3\Scripts;D:\anaconda3\envs\tf-gpu\Library\bin;C:\Windows\system32;D:\Git\cmd;C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.0\bin;C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.0\libnvvp;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\OpenSSH;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files\NVIDIA Corporation\NVIDIA NvDLISR;C:\Program Files\NVIDIA Corporation\Nsight Compute 2022.4.0;C:\Program Files\PowerShell\7;C:\Users\liquid\AppData\Local\Microsoft\WindowsApps;D:\Microsoft VS Code\bin
the integreted powershell 7's $env:PATH:
C:\Program Files\PowerShell\7;D:\anaconda3\envs\tf-gpu;D:\anaconda3\envs\tf-gpu\Library\mingw-w64\bin;D:\anaconda3\envs\tf-gpu\Library\usr\bin;D:\anaconda3\envs\tf-gpu\Library\bin;D:\anaconda3\envs\tf-gpu\Scripts;D:\anaconda3\envs\tf-gpu\bin;D:\anaconda3\condabin;C:\Program Files\PowerShell\7;D:\anaconda3\Scripts;D:\anaconda3\envs\tf-gpu\Library\bin;C:\Windows\system32;D:\Git\cmd;C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.0\bin;C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.0\libnvvp;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\OpenSSH;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files\NVIDIA Corporation\NVIDIA NvDLISR;C:\Program Files\NVIDIA Corporation\Nsight Compute 2022.4.0;C:\Program Files\PowerShell\7;C:\Users\liquid\AppData\Local\Microsoft\WindowsApps;D:\anaconda3\envs\tf-gpu\Library\bin;D:\anaconda3\Scripts;D:\Microsoft VS Code\bin;.D:\anaconda3\Scripts;D:\anaconda3\envs\tf-gpu\Library\bin;C:\Windows\system32;D:\Git\cmd;C:\Program Files\NVIDIA GPU
Computing Toolkit\CUDA\v12.0\bin;C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.0\libnvvp;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\OpenSSH;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files\NVIDIA Corporation\NVIDIA NvDLISR;C:\Program Files\NVIDIA Corporation\Nsight Compute 2022.4.0;C:\Program Files\PowerShell\7;C:\Users\liquid\AppData\Local\Microsoft\WindowsApps;D:\anaconda3\envs\tf-gpu\Library\bin;D:\anaconda3\Scripts;D:\Microsoft VS Code\bin;
the '.D' is with '.D:\anaconda3\Scripts'
Activity
hojo0590 commentedon Sep 22, 2023
Experiencing exactly the same (1.82.2) - I first had the changes a
conda init powershelldoes to one's~\Documents\WindowsPowerShell\profile.ps1to make sure envs activate in powershell under suspicion, but reverting those does not clear the error. Also running commands not related to conda on the integrated Powershell (e.g.git status) will trigger the error.notice the period in front of C - haven't dug deeper so far except my path has the period added in front of the _javapath::
What is the same for me as it is for FranciscoFang is that the period seems to be inserted as the last position of the part that is appended to my path inside VS Code - i.e. running a
$env:PATHoutside VS Code shows the part of the path after the period that shows up when running the same command inside a VS Code Powershell.kwikwag commentedon Sep 23, 2023
This happens to me too (PowerShell 5.1.19041.3031, Conda 23.5.0, via Remote SSH, additional version info below), A workaround for this is placing the following line at the top of the
profile.ps1file:Version info
Version: 1.82.2 (user setup)
Commit: abd2f3db4bdb28f9e95536dfa84d8479f1eb312d
Date: 2023-09-14T05:55:25.390Z (1 wk ago)
Electron: 25.8.1
ElectronBuildId: 23779380
Chromium: 114.0.5735.289
Node.js: 18.15.0
V8: 11.4.183.29-electron.0
OS: Windows_NT x64 10.0.19045 (Windows 10 Pro 22H2)
vsoraas commentedon Sep 25, 2023
To help whoever gets to try to debug this, the temporary workaround mentioned here seems to be effective, but may require juggling between repos if you don't catch it the first time:
PromtEngineer/localGPT#498 (comment)
EDIT:
Example errors from broken integrated terminal (which VSC comments "Shell integration failed to activate"):
Path comparison
Normal powershell window:
Integrated powershell terminal in VSCode, where the described errors occur:
By the looks of it, when the shell integration fails, the terminal duplicates (or at least ends up with duplicates of) the ENV values for its session, but in the duplicate section it mangles the python declaration with this '.C' business. All the other file paths are normal.
(Asking VSC to "Show environment contributions" produces identical PATH parameters for all terminals, regardless of the integration failing or succeeding. '.C:\Python311' is not present there, but there is a curious ";.;" present that doesn't map to any entry shown when inspecting environment variables in Windows Settings UI. Snippet below:
C:\ProgramData\chocolatey\bin;.;C:\Program Files\Docker\Docker\resources\bin;)If I succeed with the 'pip' workaround linked above, the comment from VSC will change to "Shell integration activated" and the ENV paths will be as expected (with no duplicates or mangled Python path).
starball5 commentedon Sep 25, 2023
Related on Stack Overflow: Conda Env and Python extension make WinError123 in Visual Studio Code
Also, I wonder if this is related to #11039 ?
karrtikr commentedon Sep 25, 2023
Hi all, Fix should be out in the pre-release version of the extension, use the following to try it out:
Dup of #22047.
2 remaining items
kwikwag commentedon Sep 26, 2023
Seeing that this has been "fixed" I must admit I am not that happy with this "feature" in the first place. I have personally disabled activation of environments altogether:
I'll wait until it's all ironed out. Also, the description and notification messages are quite hard to follow. I'm less comfortable with the wrong environment possibly showing up in the prompt than I am with polluting terminal history. Is there a way to choose how I'd like my environment to be activated? Can you switch this back until you have all the issues ironed out, or at least enable a flag to temporarily disable the new method while this is still under development?
Also, when this setting is enabled, it looks like the
PATHenvironment variable is modified so it repeats itself 3 times! Specifically,c:\Users\me\.vscode-server\bin\abd2f...b312d\bin\remote-cliis repeat three times. This makes little sense to me.karrtikr commentedon Sep 26, 2023
This feature is currently behind an experiment, feel free to add the following User setting to temporarily opt out:
We plan to make this the default experience going forward, and would very much appreciate it if you could help with the specifics which makes it hard to follow, or any other feedback to improve it.
That's currently a limitation we're hoping to solve in the future with microsoft/vscode#145234. But things should still work as expected even with the limiation.
anhq-nguyen commentedon Sep 26, 2023
I tried switching to pre-release version but the error still persists.
karrtikr commentedon Sep 26, 2023
@ngquocanh1197 Can you confirm that you reloaded the window and reopened terminals after install finished?
anhq-nguyen commentedon Sep 27, 2023
Kartik Raj (@karrtikr) Sorry for the confusion, it's working now. I probably forgot to reload everything.
Akut-Luna commentedon Sep 28, 2023
I tried to switch to the pre-release version and reloaded / reopened everything. It works now, but every time I open VSC I get spammed by this error messages:
karrtikr commentedon Sep 28, 2023
Please create a new issue as directed in https://github.com/microsoft/vscode-python/wiki/Reporting-a-bug and we'll be happy to take a look. Meanwhile you can switch to Pylance to unblock yourself. (Set
python.languageServersetting to Pylance)Akut-Luna commentedon Sep 28, 2023
Thanks for you help. Can you explain to some one how only ever interacted with the UI and doesn't know where to find setting files, how to set the
python.languageServerto Pylance. And maybe also how to do this?joltman61 commentedon Sep 28, 2023
I am getting very similar issue and have tried updating to the pre-release version but did not resolve it. In my case the path variable is getting duplicated as above but there is no separator being added between the existing PATH and what appears to be added as ${env:PATH}, "...C:\Users\joltman\AppData\Local\Programs\Microsoft VS Code\bin${env:PATH}`". Debugging in VS Code continues to work, but things like a "conda list" command are failing with an error like...
for entry in os.scandir(dir_path):
^^^^^^^^^^^^^^^^^^^^
OSError: [WinError 123] The filename, directory name, or volume label syntax is incorrect: 'C:\Users\joltman\AppData\Local\Programs\Microsoft VS Code\binC:\Users\joltman\Miniconda3'
I was able to disable the "Active Python Environment in all Terminals created." and then manually activate the env using "conda activate env" without seeing the issue.
karrtikr commentedon Sep 28, 2023
joltman61 You may need to reload the window.
Felix (@felix-meyer) https://code.visualstudio.com/docs/getstarted/settings
I recommend folks to create a new issue rather than comments which are less likely to be tracked.