Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Debugging Python in a C# App#2546

Unanswered
F0liveira asked this question inQ&A
Feb 6, 2025· 1 comments· 2 replies
Discussion options

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!

You must be logged in to vote

Replies: 1 comment 2 replies

Comment options

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()
You must be logged in to vote
2 replies
@F0liveira
Comment options

@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:

image

I tried several things to fix this issue but nothing worked for me. Do you have any idea what my be the problem?

@robin-moss
Comment options

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

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Category
Q&A
Labels
None yet
2 participants
@F0liveira@robin-moss

[8]ページ先頭

©2009-2025 Movatter.jp