Skip to content

integreted powershell's PATH env variables contains unexpected '.' #22073

Closed

Description

@FranciscoFang
  • VS Code Version: 1.82.2 (user setup)
  • OS Version: Windows_NT x64 10.0.19045

Steps to Reproduce:

  1. open the integreted powershell.
  2. 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

  1. hojo0590 commented on Sep 22, 2023

    @hojo0590

    Experiencing exactly the same (1.82.2) - I first had the changes a conda init powershell does to one's ~\Documents\WindowsPowerShell\profile.ps1 to 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.

    + git status
    + ~~~
        + CategoryInfo          : ObjectNotFound: (.C:String) [], DriveNotFoundException
        + FullyQualifiedErrorId : DriveNotFound
    

    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::

    C:\Users\username\AppData\Local\Programs\Microsoft VS Code\bin;C:\Users\username\Miniconda3\Library\bin;.C:\ProgramData\Oracle\Java\javapath;C:\WINDOWS\system32
    

    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:PATH outside VS Code shows the part of the path after the period that shows up when running the same command inside a VS Code Powershell.

  2. kwikwag commented on Sep 23, 2023

    @kwikwag

    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.ps1 file:

    $env:Path = $env:Path.replace('.c','.;c')
    
    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)

  3. vsoraas commented on Sep 25, 2023

    @vsoraas

    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"):

    PS E:\> cd C:
    At line:1 char:1
    + cd C:
    + ~~
        + CategoryInfo          : ObjectNotFound: (.C:String) [], DriveNotFoundException
        + FullyQualifiedErrorId : DriveNotFound
    
    PS E:\> Write-Host "Hello"
    Write-Host : Cannot find drive. A drive with the name '.C' does not exist.
    At line:1 char:1
    + Write-Host "Hello"
    + ~~~~~~~~~~
        + CategoryInfo          : ObjectNotFound: (.C:String) [], DriveNotFoundException
        + FullyQualifiedErrorId : DriveNotFound
    

    Path comparison

    Normal powershell window:

    (base) PS C:\Users\vsoraas> $Env:Path
    C:\Python311\Scripts;C:\Python311; [...] E:\MSYS2\ucrt64\bin;
    

    Integrated powershell terminal in VSCode, where the described errors occur:

    PS E:\> $Env:Path
    C:\Python311\Scripts;C:\Python311; [...] E:\MSYS2\ucrt64\bin; <-- The left part is same as above, the right part is in addition --> .C:\Python311\Scripts\;C:\Python311\; [...]
    

    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).

  4. starball5 commented on Sep 25, 2023

    @starball5

    Related on Stack Overflow: Conda Env and Python extension make WinError123 in Visual Studio Code

    Also, I wonder if this is related to #11039 ?

  5. karrtikr commented on Sep 25, 2023

    @karrtikr

    Hi all, Fix should be out in the pre-release version of the extension, use the following to try it out:

    image

    Dup of #22047.

  6. added
    bugIssue identified by VS Code Team member as probable bug
    and removed
    triage-neededNeeds assignment to the proper sub-team
    on Sep 25, 2023
  7. 2 remaining items

  8. kwikwag commented on Sep 26, 2023

    @kwikwag

    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:

    "python.terminal.activateEnvironment": false
    

    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 PATH environment variable is modified so it repeats itself 3 times! Specifically, c:\Users\me\.vscode-server\bin\abd2f...b312d\bin\remote-cli is repeat three times. This makes little sense to me.

  9. karrtikr commented on Sep 26, 2023

    @karrtikr

    This feature is currently behind an experiment, feel free to add the following User setting to temporarily opt out:

    "python.experiments.optOutFrom": ["pythonTerminalEnvVarActivation"]
    

    Also, the description and notification messages are quite hard to follow.

    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.

    Also, when this setting is enabled, it looks like the PATH environment variable is modified so it repeats itself 3 times! Specifically, c:\Users\me.vscode-server\bin\abd2f...b312d\bin\remote-cli is repeat three times. This makes little sense to me.

    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.

  10. anhq-nguyen commented on Sep 26, 2023

    @anhq-nguyen

    I tried switching to pre-release version but the error still persists.

  11. karrtikr commented on Sep 26, 2023

    @karrtikr

    @ngquocanh1197 Can you confirm that you reloaded the window and reopened terminals after install finished?

  12. anhq-nguyen commented on Sep 27, 2023

    @anhq-nguyen

    Kartik Raj (@karrtikr) Sorry for the confusion, it's working now. I probably forgot to reload everything.

  13. Akut-Luna commented on Sep 28, 2023

    @Akut-Luna

    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:

    2023-09-28 08:10:09.641 [info]   Message: Pending response rejected since connection got disposed
      Code: -32097 
    2023-09-28 08:10:09.641 [info] [Info  - 8:10:09 AM] Connection to server got closed. Server will restart.
    2023-09-28 08:10:09.641 [info] true
    2023-09-28 08:10:09.641 [info] [Error - 8:10:09 AM] Python Jedi client: couldn't create connection to server.
    2023-09-28 08:10:09.641 [info]   Message: Pending response rejected since connection got disposed
      Code: -32097 
    2023-09-28 08:10:09.642 [info] [Error - 8:10:09 AM] Restarting server failed
    2023-09-28 08:10:09.642 [info]   Message: Pending response rejected since connection got disposed
      Code: -32097 
    2023-09-28 08:10:10.023 [info] Traceback (most recent call last):
      File "c:\Users\felix\.vscode\extensions\ms-python.python-2023.17.12701009\pythonFiles\run-jedi-language-server.py", line 9, in <module>
        from jedi_language_server.cli import cli
      File "c:\Users\felix\.vscode\extensions\ms-python.python-2023.17.12701009\pythonFiles\lib\jedilsp\jedi_language_server\__init__.py", line 5, in <module>
        from importlib_metadata import version
      File "c:\Users\felix\.vscode\extensions\ms-python.python-2023.17.12701009\pythonFiles\lib\jedilsp\importlib_metadata\__init__.py", line 6, in <module>
        import zipp
      File "c:\Users\felix\.vscode\extensions\ms-python.python-2023.17.12701009\pythonFiles\lib\jedilsp\zipp\__init__.py", line 9, in <module>
        from .py310compat import text_encoding
      File "c:\Users\felix\.vscode\extensions\ms-python.python-2023.17.12701009\pythonFiles\lib\jedilsp\zipp\py310compat.py", line 5
        def _text_encoding(encoding, stacklevel=2, /):  # pragma: no cover
                                                   ^
    SyntaxError: invalid syntax
    
    2023-09-28 08:10:10.037 [info] [Error - 8:10:10 AM] Server initialization failed.
    2023-09-28 08:10:10.037 [info]   Message: Pending response rejected since connection got disposed
      Code: -32097 
    2023-09-28 08:10:10.037 [info] [Error - 8:10:10 AM] The Python Jedi server crashed 5 times in the last 3 minutes. The server will not be restarted. See the output for more information.
    2023-09-28 08:10:10.038 [info] [Error - 8:10:10 AM] Python Jedi client: couldn't create connection to server.
    2023-09-28 08:10:10.038 [info]   Message: Pending response rejected since connection got disposed
      Code: -32097 
    2023-09-28 08:10:10.038 [info] [Error - 8:10:10 AM] Restarting server failed
    2023-09-28 08:10:10.038 [info]   Message: Pending response rejected since connection got disposed
      Code: -32097 
    
  14. karrtikr commented on Sep 28, 2023

    @karrtikr

    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.languageServer setting to Pylance)

  15. Akut-Luna commented on Sep 28, 2023

    @Akut-Luna

    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.languageServer setting to Pylance)

    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.languageServer to Pylance. And maybe also how to do this?

  16. joltman61 commented on Sep 28, 2023

    @joltman61

    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.

  17. karrtikr commented on Sep 28, 2023

    @karrtikr

    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.

  18. locked as resolved and limited conversation to collaborators on Oct 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

area-terminalauthor-verification-requestedIssues potentially verifiable by issue authorbugIssue identified by VS Code Team member as probable bugexperimentingFeature is part of an experimentinfo-neededIssue requires more information from posterverifiedVerification succeeded

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions