Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to do debugging in a Python console without reloading the package in PyCharm?

PyCharm runs an interactive Python console (IPython in my case), but when I make changes in the code, PyCharm doesn't reimport the modules I've been editing, so the console runs the old code.

More so, if I have an old package installed via Run setup.py Task, Python imports the old one after import mymodule as mm in the console.

One workaround is to edit the code in a file and rerun it without the interactive console, but that's not a very elegant solution.

How can I keep the interactive console up-to date and update modules on-the-fly?

like image 708
Anton Tarasenko Avatar asked Aug 22 '14 12:08

Anton Tarasenko


People also ask

How do I use debugging mode in PyCharm?

Run your program in debug mode. Just right-click any line in the editor and select the Debug <filename> command from the context menu. After the program has been suspended, use the debugger to get the information about the state of the program and how it changes during running.

How do I use Python console in PyCharm?

You can assign a shortcut to open Python console: press Ctrl+Alt+S , navigate to Keymap, specify a shortcut for Main menu | Tools | Python or Debug Console. The main reason for using the Python console within PyCharm is to benefit from the main IDE features, such as code completion, code analysis, and quick fixes.

How do you breakpoint in PyCharm?

Set breakpointsClick the gutter at the executable line of code where you want to set the breakpoint. Alternatively, place the caret at the line and press Ctrl+F8 .


1 Answers

I'm using Python 3.4.3 in Pycharm 4.0.6 currently, and building on Anton's answer above, I add the following to my Starting script:

from importlib import reload

then you can simply use 'reload(my_module)' as you please - however this would be manual for each reload and I'm not aware of a fully automated solution if that's what you're really after.

like image 106
Chaffelson Avatar answered Nov 15 '22 17:11

Chaffelson