I am running my code in Pycharm
from Terminal. Is it possible to debug the code and put breakpoints inside the code during a run from terminal?
How to debug code running from terminal in pycharm
Asked Answered
I don't know anyway to do this through the terminal, but the way I currently do it is:
Run
>Edit Configurations
> Add new configuration (the green+
button)- Choose
Python
- Fill out
Script path
,Parameters
, and other configuration fields. - Debug the newly added configuration. (
Run
>Debug...
)
With the right configuration the result should be the same as running the script in a terminal.
I find the above process a little tedious. A PEP 553 breakpoint()
might be nicer. It requires Python 3.7 and is not implemented yet. See the related issue.
Even if the program is started outside of PyCharm, we can attach PyCharm debugger to it.
Go to Run
-> Attach to process
.
This will show a list of python process that are currently running on the system. Select the appropriate process from it.
Now PyCharm debugger is connected to that process. We can add breakpoints and debug it.
The terminal runs fast and gives error in my case so not sure how to attach a process in between that time. Before and after starting attach options shows no process. Do I need to put a sleep in between? –
Cobol
@BlueClouds Yes you can add sleep in between if your process is closing before you could attach. –
Apiculate
This should be an accepted answer because the currently accepted answer is about running debug mode in Pycharm which can be found in tons of manuals –
Dunois
© 2022 - 2024 — McMap. All rights reserved.