TL;DR: use Spyder if you want an IDE with Matlab-like features, or ipython notebook if you want to do literate programming.
Python is a general purpose scripting language that can be used for statistical analysis, numeric work, machine learning, and so much more. With packages like SciPy, matplotlib, Scikit, pandas, and TensorFlow, it’s miles ahead of Matlab, which until a few years was the reference environment for signal processing and machine learning.
Of course, Matlab is more than its scripting language; it’s an integrated development environment (IDE) which combines editing, execution, plotting, debugging, etc. If you’re thinking of migrating away from Matlab, or are fluent in R and use RStudio, perhaps you’d prefer working with an IDE.
Here I evaluate 4 IDEs for scientific Python on my Ubuntu 11.10 PC to see how they stack up to an IDE like Matlab:
- IEP 3.2
- Spyder 2.2
- PyDev 2.7 + ipython
- Enthought Canopy 1.0 (commercial)
Note: this review is a few years old. I’m in the process of updating it with new IDEs (as of June 2016). In the meantime, Spyder is a great bet.
Generally, these IDEs combine a text editor, an integrated python shell (python or ipython), support for interactive plotting via matplotlib as well as several other features to tie everything together.
Criteria for evaluation
Python has support for many features of the Matlab IDE at the language level. The interactive Python shell has support for interactive execution and integrated help (simply type
help(object)). Profiling can easily be done via the cProfile module:
import cProfile as profile profile.run('myfun()')
Given this, the most important features for a Python IDE geared toward science are:
- A kick-ass text editor with introspection, autocomplete and so forth
- Seamless integration of Python shell and text editor
- Interactive plotting via matplotlib
- Seamless debugging
- An undefinable quality of well-thought out programs that causes a zen-like experience; for lack of a better term, smoothness
IEP, the interactive editor for Python, is
a cross-platform Python IDE focused on interactivity and introspection, which makes it very suitable for scientific computing.
The most notable feature of the user interface is its support for various Run commands which mimic those of Matlab. F5 will execute the currently edited Python file, F9 the current selection, while Ctrl+Enter will execute the current cell. Cells are defined via ##, equivalent to Matlab’s %%. This is a very neat feature.
An aside on dynamic loading and execution
To work comfortably with the interface, it’s important to understand how Python loads modules and functions compared to Matlab. In Matlab, if you have changed a function and save the file, on your next call Matlab will use the new definition.
In Python, it’s different. If I have a file
testcmd.py which I import via
import testcmd, if I then change
testcmd.py, neither executing
testcmd.py nor running
import again will load the updated definition.
reload(testcmd) must be called for the definition to be updated.
That means that IEP’s various interactive run modes work best when the function to be tested and the code executing it belong in the same file. While in Matlab a script file cannot contain function definitions, in Python script files can contain functions, classes, and procedural code, so this is not as limiting as it may appear at first.
It should also be noted that when a class is redefined in Python, any objects created before then will still use the old definition. For instance:
class Bob(object): def __init__(self): self.myvar = 1 def print_bob(self): print "Old myvar is:" print self.myvar bob = Bob() bob.print_bob() class Bob(object): def __init__(self): self.myvar = 2 def print_bob(self): print "New myvar is:" print self.myvar bob.print_bob() bob2 = Bob() bob2.print_bob() #rebind bob.__class__ = Bob bob.print_bob()
Old myvar is: 1 Old myvar is: 1 New myvar is: 2 New myvar is: 1
Note that binding to the new class is accomplished via setting the
__class__ property of the old object. I wish that this information was included in the IEP tour, because it’s very important to understand these things in order to take advantage of the interactive execution.
Back to IEP
IEP has post-mortem debugging (checking the state of things when the last uncaught exception occured) via a Debug button – limited, but serviceable.
The editor is pretty good – it has auto-completion, live introspection (it knows that
bob2 has a
print_bob function), function signature hints, and it shows a tree of class/function definitions.
matplotlib is supported via the following settings in
interactive : True backend : Qt4Agg
Then setting the GUI to Qt in the shell configuration in IEP.
What IEP lacks in features, it makes up for in smoothness. Although the features are limited, they’re well thought out, and polished.
- Editor: 3/5
- Interpreter integration: 4.5/5
- Plotting: 2/5
- Debugging: 2.5/5
- Smooth: 4/5
Overall score: 3.5/5
a powerful interactive development environment for the Python language with advanced editing, interactive testing, debugging and introspection features
Perhaps the most notable feature of Spyder is that it uses ipython as its default command line environment – see here for an in-depth review of ipython and ipython Notebook. As such, it has built-in support for Matplotlib. Using ipython also alleviates some of the issues with editing modules, since ipython supports auto-reloading modules, via typing at the interpreter:
import ipy_autoreload %autoreload 2
Spyder supports running a selection (F9) and a file (F5) from within the editor, but no Ctrl+Enter for cell mode-like execution.
Spyder’s editor is excellent. It offers deep introspection, highlights errors, gives warnings, and opens up the docstring information upon calling a function. Errors and warnings are shown on the left hand side of the line number and can be inspected via clicking and holding over the error and warning icons – unintuitive, but workable. Upon highlighting a word, it automatically highlights all other instances of the word in the editor – handy for tracking variables.
The editor can find the file/line where a function was defined by holding the Ctrl button and clicking the function name – similar to the Ctrl+D – Open definition feature in Matlab.
It has support for setting breakpoints within the interface, and feeds that information to the pdb debugger.
pdb can then be manipulated via its command line interface inside ipython: c to continue, u to go up a level, q to quit, etc. New in 2.2, GUI equivalents for the debugger have been added.
It would be an ideal package were it not for its lack of polish. The project explorer – there is also an unrelated, but largely overlapping file explorer – is deeply confusing and annoying. The interface used to be messy and confusing, with toolbars for buttons you will never use – but this has been significantly improved in version 2.2, in part in response to the previous review in this very blog – kudos to the developer! I also found installation on Windows to be annoying.
To sum up:
- Editor: 4/5
- Interpretor integration: 4/5
- Plotting: 4/5
- Debugging: 4/5
- Smooth: 3/5 (up from 2/5 for version 2.0)
PyDev + ipython
PyDev is a Python IDE for Eclipse. Eclipse is kind of a meta-IDE for a bunch of languages. I wouldn’t call it smooth – it’s built like a tank. While it has a fantastic editor with deep introspection, support for refactoring and a gorgeous graphical debugger, it doesn’t play well with matplotlib. Specifically, it hangs when calling
Thus, you have to keep a separate ipython window open. A file may be run in ipython via the command:
It’s a workable, if inelegant solution. I would recommend PyDev to those doing hardcore development in Python – for more casual users, look elsewhere.
- Editor: 5/5
- Interpretor integration: 2/5
- Plotting: 0/5
- Debugging: 5/5
- Smooth: 2/5
Overall score: 2.5/5
Finally, we have a commercial editor from Enthought called Canopy, which, according to them
is a comprehensive Python analysis environment with easy installation & updates of the proven Enthought Python distribution
I installed the academic version, which required acquiring a license via my mail.mcgill.ca address. It wouldn’t open. In the command line, I get the error:
/home/patrick/Canopy/appdata/canopy-18.104.22.1680.rh5-x86_64/bin/python: symbol lookup error: /usr/lib/x86_64-linux-gnu/libgdk-x11-2.0.so.0: undefined symbol: g_source_set_name
I tried every trick in the book to get it running, but couldn’t figure it out. I figured I would try support, but Enthought redirects users to ask questions on StackOverflow, which is basically a way of saying to free users: you’re shit out of luck.
But I’m a good sport, so I decided to install it on another computer (Ubuntu 12.04LTS) to see if it would work. Here I got a different error:
QGtkStyle could not resolve GTK. Make sure you have installed the proper libraries.
And then Google wasn’t helpful, so I gave up. Easy installation, eh?
Score: minus eleventy
Canopy turned out to install fine on Windows, and I review it here.