Skip to content

debugpy cli does not work when using virtual envs #606

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
karthiknadig opened this issue Feb 11, 2025 · 6 comments
Closed

debugpy cli does not work when using virtual envs #606

karthiknadig opened this issue Feb 11, 2025 · 6 comments
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug important Issue identified as high-priority

Comments

@karthiknadig
Copy link
Member

Type: Bug

Behaviour

Activate a virutal environment in VS Code terminal. Try debugging using the activated python. It uses the wrong python.

Steps to reproduce:

  1. This in on Windows
  2. Have multiple pythons installed using windows store
  3. Create a virtual environment
  4. Load a python project and use cli debugging.
  5. If you print sys.executable you get the wrong one.

Diagnostic data

launch.json configuration

XXX

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

XXX

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

XXX

Extension version: 2025.1.2025021101
VS Code version: Code - Insiders 1.98.0-insider (b1bce46d27c96db4ad9e1a7968606118feff9abb, 2025-02-11T12:59:07.299Z)
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.): VirtualEnvironment
System Info
Item Value
CPUs Intel(R) Core(TM) i7-1065G7 CPU @ 1.30GHz (8 x 1498)
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.60GB (10.67GB free)
Process Argv --log trace --log ms-python.python=info --crash-reporter-id 4fb1ebc1-cf4c-4880-a88a-47738ec3768d
Screen Reader no
VM 0%
A/B Experiments
vsliv368cf:30146710
vspor879:30202332
vspor708:30202333
vspor363:30204092
vsc_aacf:30263846
pythonvspyt551:31179976
vscod805cf:30301675
py29gd2263:31024238
14376chatcontrol:31235589
c4g48928:30535728
vscrpc:30624061
a9j8j154:30646983
962ge761:30841072
dsvsc014:30777825
dsvsc015:30821418
h48ei257:31000450
pythontbext0:30879054
cppperfnew:30980852
pythonait:30973460
dwnewjupytercf:31046870
nativerepl1:31134653
pythonrstrctxt:31093868
nativeloc1:31118317
e80f6927:31120813
iacca1:31150324
notype1:31143044
dwcopilot:31158714
h409b430:31177054
5b1c1929:31184661
bajee813:31235726
6074i472:31201624
dwoutputs:31233690
hdaa2157:31222309
copilot_t_ci:31222730
f27dg485:31233432
g012b348:31231168
jda6j935:31233686

@github-actions github-actions bot added the triage-needed Needs assignment to the proper sub-team label Feb 11, 2025
@karthiknadig
Copy link
Member Author

I think the debugpy.ps1 should use [System.Environment], see:

$os = [System.Environment]::OSVersion
if ($os.Platform -match "Win32NT") {
    python $env:BUNDLED_DEBUGPY_PATH --listen 0 --wait-for-client $args
} else {
    python3 $env:BUNDLED_DEBUGPY_PATH --listen 0 --wait-for-client $args
}

@karthiknadig karthiknadig added bug Issue identified by VS Code Team member as probable bug important Issue identified as high-priority and removed triage-needed Needs assignment to the proper sub-team labels Feb 11, 2025
@TheOpponent
Copy link

TheOpponent commented Feb 11, 2025

I tried to recreate my venv to fix this and wasn't able to get access to debugpy on Windows 10.

(.venv) C:\Users\user\Documents\Scripts\sample>debugpy main.py
'debugpy' is not recognized as an internal or external command,
operable program or batch file.

@karthiknadig
Copy link
Member Author

@TheOpponent Do you see a terminal warning on the terminal title? This happens if the terminal did not startup with the correct flags. This PR #601 should address it.

@TheOpponent
Copy link

I did this after relaunching the terminal after installing 1.97.0.

@karthiknadig
Copy link
Member Author

$os = [System.Environment]::OSVersion.Platform
if ($os -eq [System.PlatformID]::Win32NT) {
    python $env:BUNDLED_DEBUGPY_PATH --listen 0 --wait-for-client $args
} else {
    python3 $env:BUNDLED_DEBUGPY_PATH --listen 0 --wait-for-client $args
}

@eleanorjboyd
Copy link
Member

closed by #610

@eleanorjboyd eleanorjboyd marked this as not a duplicate of #605 Feb 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue identified by VS Code Team member as probable bug important Issue identified as high-priority
Projects
None yet
Development

No branches or pull requests

3 participants