VS Code | Integrated terminal does not load PATH environment variable unless logout Windows user

01kg - Sep 15 - - Dev Community

I was working on a project on a new Windows computer, noticed python had not been installed, so I decide to install pyenv-win first then install python.

In the integrated terminal of VS Code, under my project's root directory, I followed official doc installed pyenv-win.

Then run pyenv got CommandNotFoundException.

I opened a Powershell window, pyenv works.

What an old issue of VS Code! See this 6-year-old issue.

Close all integrated terminal window (click the recycle bin button or x button), then click + button to open a new integrated terminal window?

Does not work!

Exit VS Code then open it again?

Does not work!

Close all integrated terminal window, exit VS Code then open it again?

Does not work!

In a Powershell window run code to open VS Code?

Does not work!

Set "terminal.integrated.enablePersistentSessions" to false in settings?

Does not work!

Solution (not perfect)

As Driky given
$env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User")

Yes, it works ... only for the current integrated terminal of VS Code. If click + button to open another one, still does not work.

I used this solution temporarily to finish my work. Then logout & login windows user to let VS Code refresh its integrated terminal completely.

Make the solution easier to use

  1. Open your PowerShell profile script. You can do this by running the following command in PowerShell:

    notepad $PROFILE
    
  2. Add the following line to the profile script to define the alias:

    function Ensure-Path {
        $env:Path = [System.Environment]::GetEnvironmentVariable('Path','Machine') + ';' + [System.Environment]::GetEnvironmentVariable('Path','User')
    }
    
    New-Alias ensurepath Ensure-Path
    
  3. Save and close the profile script.

  4. Restart your PowerShell session or run the profile script to apply the changes:

    . $PROFILE
    

Now, you can type ensurepath in any PowerShell window to execute the command.

. . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Terabox Video Player