Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to debug code running from terminal in pycharm

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?

like image 592
MSepehr Avatar asked Jan 30 '18 11:01

MSepehr


2 Answers

I don't know anyway to do this through the terminal, but the way I currently do it is:

  1. Run > Edit Configurations > Add new configuration (the green + button)
  2. Choose Python
  3. Fill out Script path, Parameters, and other configuration fields.
  4. 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.

like image 92
AXO Avatar answered Sep 28 '22 11:09

AXO


There is a way using python console.

To run it: Tools -> python console .. or you can find it at the bottom of the IDE.

Then press on 'Attach debugger' line in the following picture: enter image description here

Add a breakpoint in your code and then pass the file name to the cosole, like: %run my_file.py

like image 43
Minions Avatar answered Sep 28 '22 13:09

Minions