Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Step Into import statement when Python debugging in PyCharm?

import numpy as np

is just calling Includes/numpy/__init__, right?

So, how to step into this while debugging? F7 doesn't work. Setting breakpoint inside numpy doesn't work either.

like image 334
Dims Avatar asked May 22 '26 15:05

Dims


1 Answers

Lets say you have a script in a project in PyCharm where you import numpy:

import numpy as np
a = np.zeros(100)

You need to find the __ init __ .py of numpy (for instance in site-packages/numpy/__ init __.py). You can find it in External Libraries/ site-packages. It should be located right below your project folder in PyCharm Project view.

Once you have located the file, open it and set a breakpoint at the first line of a code. Code starts like this:

try:
    __NUMPY_SETUP__
except NameError:
    __NUMPY_SETUP__ = False

To be able to reach the breakpoint in the __ init __.py of numpy, go back to the script and run it in the debug mode. This will bring you to the place in __ init __.py of numpy where the breakpoint is.

like image 122
Julia Avatar answered May 24 '26 03:05

Julia



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!