The Raspberry Pi (specifically, Raspbian with desktop) comes with a few integrated development environments (IDEs) for writing, running and debugging Python scripts. I’d like to take a look at each of them and offer a comparison. Each of the three - IDLE, Geany and Thonny - seem to offer a similar set of functions, but all seem to be geared toward the beginner.
IDLE has been with Raspbian for generations as the default editor. As such, many introductory Python tutorials out there still show screenshots with IDLE. That being said, IDLE is little more than a text editor and a terminal window. In fact, editing code happens in a separate window than the terminal.
It does offer syntax highlighting but no line numbers (I consider this almost a necessity in code editors). You can look at the bottom right of the text entry window to see the current line and column, but I find it way more cumbersome to do this than have line numbers down the side of your editor. Another downside is that it only works with Python, but it does offer a step-through debugger.
I found the debugger to be not very intuitive, but it does show the internal workings of each piece of code being called (good for advanced users, not great for beginners). You can set breakpoints by starting the debugger, going back into your code, right-clicking on a line and selecting “Set Breakpoint.”
In the end, I found IDLE more trouble than it’s worth. Working on a tiny Raspberry Pi LCD made it very difficult to manage all the windows that IDLE requires.
Right away, Geany seems to be a cleaner editor than IDLE (at least on a small screen). You’ll find a variable viewer on the left, and if you tab over, you can browse files on your computer. This feature can be very helpful if you’re trying to keep track of several Python files in a project. Code editing has highlighting and line numbers. At the bottom you’ll find a few tabs, one of which includes a terminal where you can interact with your running project.
That being said, all these features, while well laid out, can clutter a small screen pretty quickly.
The good news is that Geany works with many different programming languages out of the box, so if you learn to use Geany for Python, you can easily start using it to develop C/C++, Java, HTML, Erlang, etc. The bad news is that Geany does not come with a debugger. You can install a debugging panel with
sudo apt-get install geany-plugins, but even that one does not seem to work with Python (it seems to be intended for debugging C/C++ with gdb).
It certainly has a slick interface, but the extra features to support other languages ultimately take up space and clutter your screen when real estate is at a premium. Also, the lack of a debugger makes me a sad panda.
Thonny was written from the ground up with a singular focus: to be a Python IDE for beginners. This is evident as soon as you open the program – only the editor and terminal appear in the window. At the top, you’ll see large, friendly buttons for adding a file, loading, saving, running, stopping and debugging.
The simplicity of the interface reminds me of Arduino (in a good way, as something that’s meant to be helpful for beginners). While line numbers are not present out of the box, you can enable them by clicking a checkbox in Tools > Options. Under View, you can also enable different panes to give you access to things like files, variables, etc. I would not call these panes “customizable,” but the fact that you can enable and disable them at will allows you to scale up the complexity of the interface.
The real surprise came when using Thonny’s debugger. With one click of the “Debug current script,” you are placed into a debugging mode with the ability to step through each line of code. Even better, as variables are set or changed, the debugger highlights the value of each variable.
This can be incredibly useful when writing code as a beginner to see how variables change and comparisons work. The one downside of the debugger is that it does not support traditional breakpoints. You can select Run > Run to cursor, which will interrupt the program at whichever line your cursor is on. This acts as a simple breakpoint, but only one can be set at a time.
While Thonny supports only Python, it is a breeze to use with a slick interface and a friendly debugger.
After playing with each of the default IDEs, I am a new fan of Thonny, especially when it comes to teaching Python for first-time users on the Raspberry Pi (and likely other computers, as well).
That being said, I still plan to write plenty of Python on basic text editors (Notepad++ for Windows, nano, vim, LeafPad, Midnight Commander, etc.) and call scripts from the terminal. I just learned about the existence of pdb, the Python Debugger, which requires some looking into.
How do you like to write Python? What IDE(s) do you recommend, even if it means installing it separately on something like a Raspberry Pi?