Skip to content

pythonTerminalEnvVarActivation not working with git bash on Windows #24717

@schwaerz

Description

@schwaerz

Type: Bug

Behaviour

When opening a Git Bash with a virtual python env supposed to be activated on Windows which "pythonTerminalEnvVarActivation" is enabled, it mostly won't work. It looks like there's an issue with the path translation. For me, I have the repositories located on c:\repositories. During path resolution it seems like the \r gets interpreted as a . echo $PATH will look like this : epositories/c/Users/schwaerz/home/bin:/mingw64/bin:/usr/local/bin:/usr/bin:/bin:/mingw64/bin:/usr/bin:/c/Users/schwaerz/home/bin

If I rename the c:\repositories folder, it still won't work as $PATH contains backslashes.

If I disable the experiment, the venv integration will work. However other plug-ins which need the integration (in my case: vsconan) will break.

Steps to reproduce:

  1. Be sure that the pythonTerminalEnvVarActivation experiment is enabled (which is the default if telemetry is enabled)
  2. Create some virtual python env in your workspace, e.g. in .venv
  3. Select the venv python as python interpreter
  4. Open a git bash (no need to have git bash be the default terminal)
  5. Check echo $PATH and which python. It will be wrong / broken

Diagnostic data

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

2025-01-13 16:23:19.895 [info] Telemetry level is off
2025-01-13 16:23:19.895 [info] Experiments are disabled, only manually opted experiments are active.
2025-01-13 16:23:19.895 [info] Experiment 'pythonTerminalEnvVarActivation' is active
2025-01-13 16:23:19.895 [warning] Dir "c:\repositories\foo\.pixi\envs" is not watchable (directory does not exist)
2025-01-13 16:23:19.895 [info] Python interpreter path: .\.venv\Scripts\python.exe
2025-01-13 16:23:19.895 [info] > pyenv which python
2025-01-13 16:23:19.895 [info] cwd: .
2025-01-13 16:23:21.796 [info] > & ./.venv/Scripts/Activate.ps1 ; echo 'e8b39361-0157-4923-80e1-22d70d46dee6' ; python ~/.vscode/extensions/ms-python.python-2024.23.2025011301-win32-x64/python_files/printEnvVariables.py
2025-01-13 16:23:21.796 [info] shell: powershellCore
2025-01-13 16:23:22.449 [info] > ~\AppData\Local\Programs\Python\Python313\python.exe ~/.vscode/extensions/ms-python.python-2024.23.2025011301-win32-x64/python_files/printEnvVariables.py
2025-01-13 16:23:22.449 [info] shell: powershellCore
2025-01-13 16:23:22.605 [info] Starting Pylance language server.
2025-01-13 16:23:22.822 [info] Prepending environment variable PATH in collection with c:\Users\schwaerz\.vscode\extensions\ms-python.python-2024.23.2025011301-win32-x64\python_files\deactivate\powershell;C:\repositories\foo\.venv\Scripts; {"applyAtShellIntegration":true,"applyAtProcessCreation":true}
2025-01-13 16:23:22.822 [info] Setting environment variable VIRTUAL_ENV in collection to C:\repositories\foo\.venv {"applyAtShellIntegration":true,"applyAtProcessCreation":true}
2025-01-13 16:23:22.823 [info] Setting environment variable VIRTUAL_ENV_PROMPT in collection to .venv {"applyAtShellIntegration":true,"applyAtProcessCreation":true}
2025-01-13 16:23:22.823 [info] Send text to terminal: & C:/Users/schwaerz/AppData/Local/Programs/Python/Python313/python.exe c:\Users\schwaerz\.vscode\extensions\ms-python.python-2024.23.2025011301-win32-x64\python_files\printEnvVariablesToFile.py c:\Users\schwaerz\.vscode\extensions\ms-python.python-2024.23.2025011301-win32-x64\python_files\deactivate\powershell\envVars.txt
2025-01-13 16:23:35.760 [info] Shell integration status changed, can confirm it's working.
2025-01-13 16:23:35.761 [info] Prepending environment variable PATH in collection with c:\Users\schwaerz\.vscode\extensions\ms-python.python-2024.23.2025011301-win32-x64\python_files\deactivate\powershell;C:\repositories\foo\.venv\Scripts; {"applyAtShellIntegration":true,"applyAtProcessCreation":true}
2025-01-13 16:23:35.761 [info] Setting environment variable VIRTUAL_ENV in collection to C:\repositories\foo\.venv {"applyAtShellIntegration":true,"applyAtProcessCreation":true}
2025-01-13 16:23:35.761 [info] Setting environment variable VIRTUAL_ENV_PROMPT in collection to .venv {"applyAtShellIntegration":true,"applyAtProcessCreation":true}

Extension version: 2024.23.2025011301
VS Code version: Code 1.96.2 (fabdb6a30b49f79a7aba0f2ad9df9b399473380f, 2024-12-19T10:22:47.216Z)
OS version: Windows_NT x64 10.0.26100
Modes:

  • Python version (& distribution if applicable, e.g. Anaconda): 3.12.8
  • Type of virtual environment used (e.g. conda, venv, virtualenv, etc.): Venv
  • Value of the python.languageServer setting: Pylance
User Settings


languageServer: "Pylance"

experiments
• optInto: ["pythonTerminalEnvVarActivation"]

Installed Extensions
Extension Name Extension Id Version
azure-account ms- 0.12.0
behave-vsc jim 0.6.4
better-cpp-syntax jef 1.27.1
chai-spec-generator rin 0.4.0
cmake twx 0.0.17
cmake-tools ms- 1.19.52
code-groovy mar 0.1.2
code-runner for 0.12.2
code-spell-checker str 4.0.34
cortex-debug mar 1.12.1
cpptools ms- 1.22.11
cpptools-extension-pack ms- 1.3.0
cpptools-themes ms- 2.0.0
dbclient-jdbc cwe 1.3.9
debug-tracker-vscode mcu 0.0.15
debugpy ms- 2024.14.0
dot Ste 0.0.1
Doxygen bbe 1.0.0
even-better-toml tam 0.21.2
git-graph mhu 1.30.0
githistory don 0.6.20
github-markdown-preview bie 0.3.0
gitlens eam 16.1.1
gradle-language nac 0.2.3
hexeditor ms- 1.11.1
html-preview-vscode geo 0.2.5
java red 1.38.0
jenkins-pipeline-linter-connector jan 1.2.0
jenkinsfile-support sec 0.1.0
jinja who 0.0.8
js-debug ms- 1.96.0
js-debug-companion ms- 1.1.3
jupyter ms- 2024.11.0
jupyter-keymap ms- 1.1.2
jupyter-renderers ms- 1.0.21
Kotlin mat 1.7.1
live-server ms- 0.4.15
lldb-vscode lan 0.2.3
makefile-tools ms- 0.11.13
markdown-all-in-one yzh 3.6.2
markdown-checkbox bie 0.4.0
markdown-emoji bie 0.3.1
markdown-footnotes bie 0.1.1
markdown-jira chi 1.1.0
markdown-jira-preview tra 0.0.1
markdown-mermaid bie 1.27.0
markdown-pdf yza 1.5.0
markdown-preview-github-styles bie 2.1.0
markdown-yaml-preamble bie 0.1.0
material-theme zhu 3.17.7
memory-view mcu 0.0.25
mermaid-markdown-syntax-highlighting bpr 1.7.0
node-tdd pra 0.2.4
npm-intellisense chr 1.4.5
one-monokai aze 0.5.2
pascal-formatter ale 2.9.0
peripheral-viewer mcu 1.4.6
perl ric 2.6.2
plantuml jeb 2.18.1
powershell ms- 2024.4.0
project-manager ale 12.8.0
python ms- 2024.23.2025011301
qub-msbuild qub 0.6.3
quicktask lky 3.5.8
reg ion 1.1.0
regex chr 0.5.1
remote-containers ms- 0.394.0
remote-explorer ms- 0.4.3
remote-ssh ms- 0.116.1
remote-ssh-edit ms- 0.87.0
remote-wsl ms- 0.88.5
rtos-views mcu 0.0.7
ruff cha 2025.2.0
run-current-test asv 0.2.0
test-adapter-converter ms- 0.2.1
todotasks san 0.5.0
togglehs bbe 0.1.2
vsc-tasks wal 0.9.0
vscode-azureresourcegroups ms- 0.10.2
vscode-clangd llv 0.1.33
vscode-commons red 0.0.6
vscode-coverage-gutters rya 2.12.0
vscode-docker ms- 1.29.3
vscode-eslint dba 3.0.10
vscode-gradle vsc 3.16.4
vscode-groovy Arg 0.0.1
vscode-groovy-lint Nic 3.3.1
vscode-instant-markdown dba 1.4.7
vscode-java-debug vsc 0.58.1
vscode-java-dependency vsc 0.24.1
vscode-java-pack vsc 0.29.0
vscode-java-test vsc 0.43.0
vscode-js-profile-table ms- 1.0.10
vscode-jupyter-cell-tags ms- 0.1.9
vscode-jupyter-slideshow ms- 0.1.6
vscode-lldb vad 1.11.1
vscode-markdownlint Dav 0.58.1
vscode-maven vsc 0.44.0
vscode-mysql-client2 cwe 8.1.1
vscode-perl cfg 1.19.0
vscode-pylance ms- 2024.12.1
vscode-reveal evi 4.3.3
vscode-test-explorer hbe 2.22.1
vscode-yaml red 1.15.0
vsconan afr 1.3.1
xml Dot 2.5.1
System Info
Item Value
CPUs 12th Gen Intel(R) Core(TM) i7-12800H (20 x 2803)
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
webnn: disabled_off
Load (avg) undefined
Memory (System) 31.58GB (16.97GB free)
Process Argv c-app/
Screen Reader no
VM 0%

Metadata

Metadata

Assignees

Labels

info-neededIssue requires more information from postertriage-neededNeeds assignment to the proper sub-team

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions