I use Visual Studio 2017 (V15.8.9) with python tools. When I try to remote debug using ptvsd I see different versions depending where I import ptvsd.
When opening a python console in visual studio in my current environment and import ptvsd
, i allways get version 3.2.1.0 which is installed in %ProgramFiles(x86)%\microsoft visual studio\2017\community\common7\ide\extensions\microsoft\python\core\ptvsd\
.
If I install ptvsd in the python environment, the current version 4.2.0 is correctly installed. But when I repeat the above import statement I still see Version 3.2.1.0. The packet version installed in the core seems to override the newer package installed in the environment.
On the remote machine the current version of PTVSD is installed and used. This leads to a version mismatch.
When using PTVSD 3.2.1 on both machines, visual studio complains when starting the debug that there would be a newer version (4.1.1a9) installed on the local machine.
Utilize legacy debugger. This was the only option which worked for me in conjunction with Python 3.4 and Microsoft Visual Studio 2017 and 2019. Sadly, Microsoft droped support for the ptvsd debugger completely with Visual Studio 2022.
To enable the legacy debugger, go to Debug -> Options... -> Python -> Debugging
and check Use legacy debugger
. In both VS2017 and VS2019, the legacy debugger is based on ptvsd 3.2.1.0
(with some auxiliary scripts referring to 3.1 and 3.2). You need to import that one in your Python project before attaching to a running Python process.
It appears from Microsoft's documentation (see https://learn.microsoft.com/en-us/previous-versions/visualstudio/visual-studio-2017/python/debugging-python-in-visual-studio?view=vs-2017#use-the-legacy-debugger) and source code of the debugger shipped with Visual Studio 2017 that the Python debugger built into Visual Studio 2017 was based on ptvsd 4.1.1a9 debugger. In my distribution of VS2017 (Professional Edition), the latest Python debugger utilized in Visual Studio 2017 is in fact located at %ProgramFiles(x86)%\microsoft visual studio\2017\Professional\common7\ide\extensions\microsoft\python\core\Packages\ptvsd\
, (see _version.py
). However, attempts to use ptvsd 4.1.1a9, 4.1.1 or more up-to-date versions like 4.3.2 result in either failures to connect to the Python process to be debugged, or in frequent freezes of Visual Studio. I would name such debugger support highly experimental.
Starting with Visual Studio 2019, Microsoft apparently dropped support for then up-to-date releases of ptvsd in favour of debugpy
which they picked as the default Python debugger. In some cases (Python 3.4, for example, for which debugpy was never available), the only option there is to drop to the legacy debugger. The legacy debugger stayed the same as in Visual Studio 2017, i.e. ptvsd 3.2.1.0.
You are indeed right that the legacy version of ptvsd built into Visual Studio is stored at %ProgramFiles(x86)%\microsoft visual studio\2017\community\common7\ide\extensions\microsoft\python\core\ptvsd\
(replace 2017
with 2019 for VS2019 and Professional
with your edition of the VS). This package is automatically imported in any Python Interactive Window when importing ptvsd, no matter which version is installed in the target Python environment - I suppose this is a bug.