- Notifications
You must be signed in to change notification settings - Fork748
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
-
Hi everyone, I'm working on a C# application in Visual Studio 2022 that integrates with Python using Python.NET. However, I'm facing issues when trying to debug the Python code from C#. Specifically, I'm unable to step through the Python code or set breakpoints effectively. Could anyone provide guidance or suggestions on how to debug Python code within a C# application using Python.NET? I've seen the following tutorial but it is from 2017 and it didn't seem straight forward to do:https://github.com/pythonnet/pythonnet/wiki/Various-debugging-scenarios-of-embedded-CPython Thanks in advance for your help! |
BetaWas this translation helpful?Give feedback.
All reactions
Replies: 1 comment 2 replies
-
We use debugpy and vscode to allow debugging of the Python code defdebug(port:int=5678):""" Enable debugging for the python script Use the example launch.json configuration below to connect from VSCode: ``` { "version": "0.2.0", "configurations": [ { "name": "Python Debugger: Attach using Process Id", "type": "debugpy", "request": "attach", "connect": { "host": "localhost", "port": 5678 }, "justMyCode": false } ] } """importdebugpydebugpy.listen(port)debugpy.wait_for_client()debugpy.breakpoint() |
BetaWas this translation helpful?Give feedback.
All reactions
-
@robin-moss thanks for your help. I tried your approach but for some reason when I run my C# app in debug mode and then do the Attach Process I have the following issue: I tried several things to fix this issue but nothing worked for me. Do you have any idea what my be the problem? |
BetaWas this translation helpful?Give feedback.
All reactions
-
You have to debug the Python code as if it were a Python application, not a C# one. So if you want to debug both Python and C#, you'll need to run two debuggers, we use vscode for the Python side |
BetaWas this translation helpful?Give feedback.