0

I installed a Python package and would like to debug it using PyCharm. Typically I can simply set breakpoints and debugging works fine. However, the package (let's call it module_name) I am using now has to be called from the terminal, or in a Python script using os.system("module_name --additional_args"). It runs fine like this, but if I put a breakpoint in module_name.py at entry_func():

def get_parser():
...

def entry_func(args=None):
...

if __name__ == "__main__":
    entry_func()

The breakpoint is ignored. Why is that? And how can I debug this module otherwise?

I tried to set a breakpoint at entry_func(), but the program did not stop there.

Adriaan
  • 17,741
  • 7
  • 42
  • 75
  • 3
    Breakpoints are meant to be used with your editor (or debugging program), not directly from terminal using the python interpreter. – Itération 122442 Aug 18 '23 at 09:28
  • Checkout this: https://www.jetbrains.com/help/pycharm/debugging-your-first-python-application.html#where-is-the-problem – Itération 122442 Aug 18 '23 at 09:29
  • Thanks, the debugger works fine otherwise. So that is not the issue. 'Breakpoints are meant to be used with your editor (or debugging program), not directly from terminal using the python interpreter.' Ok, so how can I debug this code? – martin_utrecht Aug 18 '23 at 09:32
  • Can I somehow run the package in a different way such that I CAN use the debugger? – martin_utrecht Aug 18 '23 at 09:33
  • You can run it via `pdb` to use a terminal-based debugger. PyCharm and others use it internally – mousetail Aug 18 '23 at 09:35
  • Ok thanks. I added 'import pdb' to module_name.py and added pdb.set_trace() here: 'if __name__ == "__main__": pdb.set_trace() entry_func()' still nothing happens. Am I using this wrongly? – martin_utrecht Aug 18 '23 at 09:44
  • Pycharm "hides" a few steps, though if you look at their command line run, when you click the debugging, you'd figure out some of their "tips & tricks". Using the command line, you're to run it like this https://stackoverflow.com/a/48465616/6681261 – Adji_PA Aug 18 '23 at 09:56
  • Thank you for the link! I managed to get it to run and use breakpoints with breakpoint(). – martin_utrecht Aug 18 '23 at 11:13

0 Answers0