The way to get fast debugging sessions in PyCharm (Professional edition) is to use remote debugging, similar to pdb.set_trace()
.
In the Run/Debug Configurations dialogue, create a Remote Debug configuration. The dialogue contains the instructions, which I will repeat here completeness sake:
Add pycharm-debug.egg
from the PyCharm installation to the Python path.
Add the following import statement:
import pydev
Add the following command to connect to the debug server:
pydevd.settrace('localhost', port=$SERVER_PORT, stdoutToServer=True, stderrToServer=True)
These strings can be copied from the dialogue and pasted into the source. When you choose the host and server port in the dialogue, the pasteable strings will update themselves. Of course, they can also be concatenated to a oneliner using ;
.
After the settrace()
method has been run, the breakpoints you have set in PyCharm will become active.
So, where's the file pycharm-debug.egg
? Somewhere in the near vicinity of the PyCharm binary. In OS X, you will find the file within the Contents/debug-eggs
directory within PyCharm.app. I assume other PyCharm distributions have a similar directory.
If you're running the application using a virtualenv, install the egg using easy_install
.
If you prefer to run your application within PyCharm (stdout in the PyCharm console is useful), then add the path to the egg file to the Project Interpreter's file paths.