Hi all Python developers!
In Eclipse with PyDev it is possible to edit a Python file while debugging. On save, the PyDev debugger will reload the updated code into the running program and uses my new code. How can I do the same thing in JetBrains PyCharm (using Community Edition)?
Eclipse / PyDev writes an output like this when I do that:
pydev debugger: Start reloading module: "MyWidget" ... pydev debugger: Updated function code: <function close at 0x055F4E70> pydev debugger: reload finished
I searched settings and web and could not find any hint. Very glad about any idea. Thx.
Edit: I found out in Eclipse/PyDev one has to be in debug mode to be able to use this feature. I tested in PyCharm, but there was no reload done.
Advertisement
Answer
After all I found a useful and acceptable workaround for my question. It works in PyCharm Community Edition 3.1.2 and I assume it will do in commercial edition as well. I tested on a mid-scale project using Python 2.7.6, PySide (Qt) with one main window and 20+ widgets, tabs, whatever. Follow these steps…
- Work in PyCharm on a python project :-)
- Execute your code in Debug mode (did not tried Release so far)
- Edit some code in one your modules imported during the life of your program
- Make your program pause. To achieve this, you can click the “Pause” button of in PyCharms Debug view and then any place in your applications main window where it would need to do something (for example on a tab header). If you have a long a running task and no UI, you may place a breakpoint in a place your program often comes by.
- In the Debug view, switch to the Console tab. There is a button on the left Show command line. Click this.
- In the console, type in reload(MyModifiedModule) if this call fails, write import MyModifiedModule and try again.
- Click resume in PyCharm.
- Try the code you fixed.
There are some restrictions on this… It won’t fix changes in your main method or main window, cause it won’t be created again. In my tests I could not reload widgets from Qt. But it worked for classes like data containers or workers.
May the force be with you as you try this and do not hesitate to add your experiences.