0

I'm facing a very annoying issue with Visual Studio 2022. Here's how to replicate it.

Folder contents:

test-debugpy-issue
|   test-debugpy-issue.sln
|   
\---test-debugpy-issue
        cli.py
        test-debugpy-issue.pyproj
        test_debugpy_issue_simplified.py

Contents of cli.py:

print("hello world")

Contents of test_debugpy_issue_simplified:

import subprocess
import os
import json

print(os.getpid())
input()

configArgs = ["python", "cli.py"]

ret_code=0
while ret_code==0:
    ret_code = subprocess.call(configArgs, shell=False, universal_newlines=True)
    print(ret_code)

In order to replicate the issue, carry out the following steps:

  • Open up a Powershell or CMD terminal
  • Run python .\test_debugpy_issue_simplified.py
  • Copy the provided PID
  • In Visual Studio 2022 under Debug > Attach to Process, paste the PID, select the process as shown below:

enter image description here

  • Click Attach, then wait in the Output window until the process has successfully attached. This apparently requires multiple attempts:

enter image description here

  • Go back into your Powershell and CMD terminal and press Enter
  • The following error should appear:

0.47s - Error importing debugpy._vendored.force_pydevd (with sys.path entry: 'c:\program > files\microsoft visual studio\2022\professional\common7\ide\extensions\microsoft\python\core') Traceback (most recent call last): File "c:\program files\microsoft visual studio\2022\professional\common7\ide\extensions\microsoft\python\core\debugpy_vendored\pyde> vd_pydevd_bundle\pydevd_defaults.py", line 60, in on_pydb_init import(module_name) ModuleNotFoundError: No module named 'debugpy'

I've found this issue on Github which describes a similar problem, but it's from the Vs Code repo. I'm not using VS Code.

Why is this happening and how can I fix it ?

user32882
  • 5,094
  • 5
  • 43
  • 82
  • The effect of my test here is that after running the python program, the process is successfully attached at once, and when I try to attach again later, the program and the button are grayed out. The python program did not report an error. – Bowman Zhu-MSFT Apr 07 '23 at 09:45
  • 1
    Professional, but I don't think that matters now. You mind deleting some of your earlier comments? The discussion is becoming needlessly long. – user32882 Apr 07 '23 at 09:55
  • You can try to reinstall the python components and what about global install the debugpy? :) – Bowman Zhu-MSFT May 09 '23 at 10:10
  • @BowmanZhu-MSFT no offense, but that's almost as bad as "Did you try restarting your computer?" – user32882 May 09 '23 at 10:46

1 Answers1

0

I followed your steps and replicate the issue on my side. I installed the package debugpy and tried to attach the process with debugger again, i found the error message disappeared and it entered debug mode. You can use this command to check if there's available debugpy in your machine:

pip show debugpy

enter image description here

install debugpy:

 pip install debugpy
Dou Xu-MSFT
  • 880
  • 1
  • 1
  • 4