microsoft / vscode-python

Python extension for Visual Studio Code
https://aka.ms/pvsc-marketplace
MIT License
4.25k stars 1.15k forks source link

Gitbash terminal not opening to workspace folder. #23382

Open dmurphyinsaas opened 1 month ago

dmurphyinsaas commented 1 month ago

Type: Bug

Behaviour

When I open a Gitbash terminal window, rather than the path being set to current workspace directory as before, it is being set to some C:/Users/myuser/AppData/Local/Programs/Microsoft VS Code path and it appears some venv is active.

Steps to reproduce:

  1. Create new Folder and open this folder in VS code
  2. Open Gitbash terminal window (Opens to workspace folder as expected)
  3. Create venv python -m venv venv
  4. Create a python file touch main.py
  5. Open this file from VS Code file explorer.
  6. Terminal name turns yellow and on hover there is link to relaunch, click this relaunch terminal link.
  7. Terminal relaunches, this time some venv is activated and the path is set to C:/Users/myuser/AppData/Local/Programs/Microsoft VS Code

Diagnostic data

launch.json configuration

``` no launch.json ```

Output for Python in the Output panel (ViewOutput, change the drop-down the upper-right of the Output panel to Python)

``` 2024-05-08 11:58:29.486 [info] Experiment 'pythonaacf' is active 2024-05-08 11:58:29.486 [info] Experiment 'pythonCreateEnvOnPipInstall' is active 2024-05-08 11:58:29.486 [info] Experiment 'pythonRecommendTensorboardExt' is active 2024-05-08 11:58:29.486 [info] Experiment 'pythonREPLSmartSend' is active 2024-05-08 11:58:29.486 [info] Experiment 'pythonTerminalEnvVarActivation' is active 2024-05-08 11:58:29.486 [info] Experiment 'pythonTestAdapter' is active 2024-05-08 11:58:29.486 [info] Default formatter is set to null for workspace c:\Temp\TestVS3 2024-05-08 11:58:29.486 [info] > hatch env show --json 2024-05-08 11:58:29.486 [info] cwd: . 2024-05-08 11:58:29.486 [info] Python interpreter path: ~\.pyenv\pyenv-win\versions\3.11.3\python.exe 2024-05-08 11:58:29.533 [info] > conda info --json 2024-05-08 11:58:29.567 [info] > ~\.pyenv\pyenv-win\versions\3.11.3\python.exe -I ~\.vscode\extensions\ms-python.python-2024.7.11291009\python_files\get_output_via_markers.py ~\.vscode\extensions\ms-python.python-2024.7.11291009\python_files\interpreterInfo.py 2024-05-08 11:58:29.601 [info] > .\venv\Scripts\python.exe -I ~\.vscode\extensions\ms-python.python-2024.7.11291009\python_files\get_output_via_markers.py ~\.vscode\extensions\ms-python.python-2024.7.11291009\python_files\interpreterInfo.py 2024-05-08 11:58:29.788 [info] > ~\.pyenv\pyenv-win\bin\pyenv which python 2024-05-08 11:58:29.788 [info] cwd: . 2024-05-08 11:58:30.316 [info] > . ./venv/Scripts/activate && echo 'e8b39361-0157-4923-80e1-22d70d46dee6' && python ~/.vscode/extensions/ms-python.python-2024.7.11291009/python_files/printEnvVariables.py 2024-05-08 11:58:30.316 [info] shell: bash 2024-05-08 11:58:30.498 [info] > ~\.pyenv\pyenv-win\versions\3.10.11\python.exe ~/.vscode/extensions/ms-python.python-2024.7.11291009/python_files/printEnvVariables.py 2024-05-08 11:58:30.498 [info] shell: bash 2024-05-08 11:58:30.591 [info] Setting environment variable MSYS in collection to disable_pcon disable_pcon {"applyAtShellIntegration":true,"applyAtProcessCreation":true} 2024-05-08 11:58:30.591 [info] Prepending environment variable PATH in collection with c:\Users\asus\.vscode\extensions\ms-python.python-2024.7.11291009\python_files\deactivate\bash;C;C:\Temp\TestVS3\venv\Scripts;C:\Program Files\Git\mingw64\bin;C:\Program Files\Git\usr\bin;C:\Users\asus\bin; {"applyAtShellIntegration":true,"applyAtProcessCreation":true} 2024-05-08 11:58:30.591 [info] Prepending environment variable PS1 in collection with (venv) {"applyAtShellIntegration":true,"applyAtProcessCreation":false} 2024-05-08 11:58:30.591 [info] Setting environment variable PWD in collection to C:/Users/asus/AppData/Local/Programs/Microsoft VS Code {"applyAtShellIntegration":true,"applyAtProcessCreation":true} 2024-05-08 11:58:30.591 [info] Setting environment variable PYTHONIOENCODING in collection to utf-8 {"applyAtShellIntegration":true,"applyAtProcessCreation":true} 2024-05-08 11:58:30.591 [info] Setting environment variable PYTHONUNBUFFERED in collection to 1 {"applyAtShellIntegration":true,"applyAtProcessCreation":true} 2024-05-08 11:58:30.591 [info] Setting environment variable VIRTUAL_ENV in collection to C:\Temp\TestVS3\venv {"applyAtShellIntegration":true,"applyAtProcessCreation":true} 2024-05-08 11:58:30.591 [info] Setting environment variable VIRTUAL_ENV_PROMPT in collection to (venv) {"applyAtShellIntegration":true,"applyAtProcessCreation":true} 2024-05-08 11:58:30.592 [info] Send text to terminal: C:/Users/asus/.pyenv/pyenv-win/versions/3.10.11/python.exe c:\Users\asus\.vscode\extensions\ms-python.python-2024.7.11291009\python_files\printEnvVariablesToFile.py c:\Users\asus\.vscode\extensions\ms-python.python-2024.7.11291009\python_files\deactivate\bash\envVars.txt 2024-05-08 11:58:31.789 [info] Starting Pylance language server. 2024-05-08 11:58:31.941 [info] Python interpreter path: c:\Temp\TestVS3\venv\Scripts\python.exe 2024-05-08 11:59:00.599 [error] Failed to initialize deactivate script C:\Program Files\Git\bin\bash.exe Error: "c:\Users\asus\.vscode\extensions\ms-python.python-2024.7.11291009\python_files\deactivate\bash\envVars.txt" file not created at Timeout. (c:\Users\asus\.vscode\extensions\ms-python.python-2024.7.11291009\out\client\extension.js:2:273765) at listOnTimeout (node:internal/timers:569:17) at processTimers (node:internal/timers:512:7) ```

Output for Python Debugger in the Output panel (ViewOutput, change the drop-down the upper-right of the Output panel to Python Debugger)

``` 2024-05-08 11:58:29.522 [info] Name: Python Debugger 2024-05-08 11:58:29.523 [info] Module: debugpy ```

Extension version: 2024.7.11291009 VS Code version: Code 1.89.0 (b58957e67ee1e712cebf466b995adf4c5307b2bd, 2024-05-01T02:09:22.859Z) OS version: Windows_NT x64 10.0.22631 Modes:

User Settings

``` languageServer: "Pylance" ```

Installed Extensions |Extension Name|Extension Id|Version| |---|---|---| |.NET Install Tool|ms-dotnettools.vscode-dotnet-runtime|2.0.5| |C#|ms-dotnettools.csharp|2.28.11| |ChatGPT - Genie AI|genieai.chatgpt-vscode|0.0.10| |Code Spell Checker|streetsidesoftware.code-spell-checker|3.0.1| |Dev Containers|ms-vscode-remote.remote-containers|0.362.0| |Docker|ms-azuretools.vscode-docker|1.29.1| |DotENV|mikestead.dotenv|1.0.1| |Draw.io Integration|hediet.vscode-drawio|1.6.6| |Git History|donjayamanne.githistory|0.6.20| |GitHub Actions|github.vscode-github-actions|0.26.2| |GitHub Copilot|GitHub.copilot|1.187.0| |GitHub Copilot Chat|GitHub.copilot-chat|0.15.0| |GitHub Pull Requests|GitHub.vscode-pull-request-github|0.88.0| |GitLens — Git supercharged|eamodio.gitlens|14.9.1| |IntelliCode|VisualStudioExptTeam.vscodeintellicode|1.3.1| |IntelliCode API Usage Examples|VisualStudioExptTeam.intellicode-api-usage-examples|0.2.8| |JavaScript Debugger|ms-vscode.js-debug|1.89.0| |JavaScript Debugger Companion Extension|ms-vscode.js-debug-companion|1.1.2| |Jupyter|ms-toolsai.jupyter|2024.4.0| |Jupyter Cell Tags|ms-toolsai.vscode-jupyter-cell-tags|0.1.9| |Jupyter Keymap|ms-toolsai.jupyter-keymap|1.1.2| |Jupyter Notebook Renderers|ms-toolsai.jupyter-renderers|1.0.17| |Jupyter Slide Show|ms-toolsai.vscode-jupyter-slideshow|0.1.6| |Mocha sidebar|maty.vscode-mocha-sidebar|0.22.2| |Pylance|ms-python.vscode-pylance|2024.5.1| |Python|ms-python.python|2024.7.11291009| |Python Debugger|ms-python.debugpy|2024.6.0| |Rainbow CSV|mechatroner.rainbow-csv|3.11.0| |Swagger Viewer|Arjun.swagger-viewer|3.1.2| |Table Visualizer for JavaScript Profiles|ms-vscode.vscode-js-profile-table|1.0.9| |Test Adapter Converter|ms-vscode.test-adapter-converter|0.1.9| |Test Explorer UI|hbenl.vscode-test-explorer|2.21.1| |vscode-pdf|tomoki1207.pdf|1.2.2| |WSL|ms-vscode-remote.remote-wsl|0.88.2| |YAML|redhat.vscode-yaml|1.14.0|
System Info |Item|Value| |---|---| |CPUs|AMD Ryzen 5 5500U with Radeon Graphics (12 x 2096)| |GPU Status|2d_canvas: enabled
canvas_oop_rasterization: enabled_on
direct_rendering_display_compositor: disabled_off_ok
gpu_compositing: enabled
multiple_raster_threads: enabled_on
opengl: enabled_on
rasterization: enabled
raw_draw: disabled_off_ok
skia_graphite: disabled_off
video_decode: enabled
video_encode: enabled
vulkan: disabled_off
webgl: enabled
webgl2: enabled
webgpu: enabled| |Load (avg)|undefined| |Memory (System)|15.38GB (3.25GB free)| |Process Argv|--folder-uri file:///c%3A/Users/asus/Documents/github/insaas/insaas-notebooks-experiments --crash-reporter-id a9eaff0c-8dbb-48f1-a524-0a5dc444f644| |Screen Reader|no| |VM|0%|
A/B Experiments ``` vsliv368:30146709 vspor879:30202332 vspor708:30202333 vspor363:30204092 vswsl492:30256859 vstes627:30244334 vscoreces:30445986 vscod805cf:30301675 binariesv615:30325510 vsaa593cf:30376535 py29gd2263:31024239 c4g48928:30535728 azure-dev_surveyone:30548225 962ge761:30959799 pythongtdpath:30769146 welcomedialog:30910333 pythonidxpt:30866567 pythonnoceb:30805159 asynctok:30898717 pythontestfixt:30902429 pythonregdiag2:30936856 pyreplss1:30897532 pythonmypyd1:30879173 pythoncet0:30885854 h48ei257:31000450 pythontbext0:30879054 accentitlementsc:30995553 dsvsc016:30899300 dsvsc017:30899301 dsvsc018:30899302 cppperfnew:31000557 dsvsc020:30976470 pythonait:31006305 chatpanelt:31018789 dsvsc021:30996838 01bff139:31013167 pythoncenvptcf:31039767 dwnewjupyter:31039675 ```
anthonykim1 commented 1 month ago

Hello @dmurphyinsaas Thanks for filing the issue. Is gitbash set as your default terminal profile? If so, try switching the default to something else like pwsh,bash, etc Potentially related: https://github.com/microsoft/vscode-python/issues/22910 https://github.com/microsoft/vscode-python/issues/23008

dmurphyinsaas commented 1 month ago

Thank you for your response. Yes, I do have gitbash as my default terminal profile. When I change the default profile to pwsh, then I can open bash terminals and they are at the workspace folder path. This has only been an issue in the past week. Do you guys know the cause ? Is there likely to be a fix ? TIA

hiderline commented 1 month ago

I faced the same problem 3 days ago, after upgrade ms-python from v2024.4.1 to 2024.6.0 Rollback to previous version didn't help. I use git bash and venv as well. Next day after upgrade, after project opening, there shown some venv is activated and the path is set to

(venv) user@DESKTOP-NAME MINGW64 C:/Users/userName/AppData/Local/Programs/Microsoft VS Code

'which python' command said that global python is used print(sys.prefix) - said that project's (venv) is used/activated but 'pip list' command shows again on global environment if I run simple script - there shown, that python from (venv) was used.

deactivate command gives following result: grep: /c/Users/{userName}/.vscode/extensions/ms-python.python-2024.6.0/python_files/deactivate/bash/envVars.txt: No such file or directory - shown triple times and strange (venv) is deactivated then and jumps directly to proper project directory:

user@DESKTOP-NAME MINGW64 C:/Project/Folder Then after I can activate/deactivate project properly.

By the way, if during terminal start-up or relaunch, when strange (venv) is active, I go 'cd c:/Project/Folder' and try to activate proper project's (venv), than I get 2 (venv) activated! As following:

(venv) (venv) user@DESKTOP-NAME MINGW64 C:/Users/userName/AppData/Local/Programs/Microsoft VS Code

divyam25 commented 1 month ago

Oh my god. Since last week I am extremely irritated by this issue. My git bash is opening to "C:/Users/userName/AppData/Local/Programs/Microsoft VS Code" right after opening a python file in a given folder (more specifically, a "reactivating terminal" routine starts right after I click a python file and gitbash path jumps from current folder to the path that I just mentioned). I have tried literally everything, but this is not getting fixed. I have lost a lot of manhours on this. @hiderline describes the EXACT SAME issue I am facing. this is only happening since last week I suppose after upgrading to latest python extension.

oribay-iker commented 1 month ago

Same here, Git Bash with a venv that worked just fine until a couple of weeks ago. In my case I had manually set up a cd to specific folder in bash.bashrc located in "C:\Program Files\Git\etc".

The cd works, if I run pwd I can see i'm in the correct location, but the command prompt of git bash says "C:\Program Files\Microsoft VS Code"

Okhnovsky commented 1 month ago

Hi everyone! I had the same problem. My git bash was opening to "C:/Users/userName/AppData/Local/Programs/Microsoft VS Code" with active venv. Its happened after update python extensions to 2024.6.0 To solve this problem you should to do this in VS Code:

Kill your terminal and launch a new one

anthonykim1 commented 1 month ago

Hello everyone, thanks for looking into this issue. Please note that Gitbash is not currently officially supported by Python extension, so please consider switching your default terminal to other such as cmd, bash, zsh, etc Reference: https://github.com/microsoft/vscode-python/issues/22908 We may support Gitbash once we have more time/bandwidth in doing so.

griffinator76 commented 1 month ago

@anthonykim1 Gitbash has been the standard terminal everywhere I have worked using VS Code so it's surprising to hear you don't support this.

anthonykim1 commented 1 month ago

@griffinator76 Yes, it seems pretty obvious how many people want proper Gitbash support, so I will be bringing this up to the team.

monk-time commented 1 month ago

@anthonykim1 I assumed after VSCode v1.89 enabled shell integration for Git Bash this meant it would become fully supported in the extension too?

I really hope the team would reconsider. I don't know if you have any metrics around this but I expect Git Bash to be the most common shell on Windows, which makes it really strange that it is not properly supported. The UX using it with the Python extension is quite miserable too, with many glitches around venv activation: "Re-activating terminals" taking a long time, sometimes the "(venv)" label is missing, sometimes it is not activated properly or cannot be deactivated cleanly. There have been many issues filed here about those problems but almost all of them got dismissed.

ZdravekSprite commented 1 month ago

It's a little annoying, but it's incorrect that bash opens the wrong folder. True, at the beginning of the prompt, instead of the current folder, it shows the path to the folder where the vs code is installed (which is the annoying part), but bash itself is opened in the folder where it should be. You can check with a simple ls. The problem is only in the wrong representation. A quick solution is to just enter a folder and exit (eg cd venv cd ..)

gabrieljreed commented 3 weeks ago

@ZdravekSprite I've found that I can actually just do cd . and it refreshes properly!

NeerajKrGoswami commented 2 weeks ago

Yes cd . works for me too, but it needs to be fixed.

TheSylvester commented 3 days ago

@ZdravekSprite I've found that I can actually just do cd . and it refreshes properly!

Thank you! This is much faster than disabling Shell Integration and having to source .venv/Scripts/activate every damned time... cd . is much faster...

super weird that it's just reading the wrong string for the directory, and only initially...

shivamjagdishsingh commented 15 hours ago

Hi everyone! I had the same problem. My git bash was opening to "C:/Users/userName/AppData/Local/Programs/Microsoft VS Code" with active venv. Its happened after update python extensions to 2024.6.0 To solve this problem you should to do this in VS Code:

  • ctrl + shift + P
  • Terminal: Configure Terminal Settings

  • Scroll down until "Shell Integration" image
  • And remove tick

Kill your terminal and launch a new one

Worked for me. Thank you. Will update if issue persists.

TheSylvester commented 12 hours ago

Turning off Shell Integration removes automated virtual environment launching.

...It was deciding between typing source .venv/Scripts/activate or cd .

On Thu, Jul 4, 2024 at 10:34 AM shivam singh @.***> wrote:

Hi everyone! I had the same problem. My git bash was opening to "C:/Users/userName/AppData/Local/Programs/Microsoft VS Code" with active venv. Its happened after update python extensions to 2024.6.0 To solve this problem you should to do this in VS Code:

Kill your terminal and launch a new one

Worked for me. Thank you. Will update if issue persists.

— Reply to this email directly, view it on GitHub https://github.com/microsoft/vscode-python/issues/23382#issuecomment-2209139604, or unsubscribe https://github.com/notifications/unsubscribe-auth/AH5JQ324IQAD5LOMGCS4RP3ZKVMPZAVCNFSM6AAAAABHMYERNWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDEMBZGEZTSNRQGQ . You are receiving this because you are subscribed to this thread.Message ID: @.***>