I recently saw a poll on /r/Python, about how many people used IDLE, which is sort of the default IDE Python comes with. I used IDLE for a long time, but its shortcomings start to catch up with you:
- Pressing up moves the cursor up, and doesn’t run the last instruction (which is the default behaviour on most command lines)
- Working with files/directories on your disk is a nightmare (you have to use horrible ways like os.get_cwd or os.chdir).
- The GUI is ugly. Real ugly
While there are other IDEs, many require you to spend six hours creating a project, when all you want to do is run 5 lines of code.
I discovered IPython by mistake, and ignored it at first. This is because unlike other IDEs, there aren’t people shouting OMG! IPython is the best. Well, it’s time to change that.
OMG! IPython is the Best
IPython is really slick, with a lot of cool features. We’ll only go over a few of them. My goal is to convince you to dump IDLE for IPython.
IPython comes in two flavors: QT Console which runs as a desktop app, and Notebook, which runs as a web service. Let’s looks at QT Console first:
Code completion
If you import a library, say Pandas, and forget which function reads a csv file, pressing tab will give you all possible choices:
This works with local variables as well:
Great directory/file access
IPython supports most Linux commands, so you can run commands like cd, pwd, ls etc. It makes changing directories, looking up files so easy:
In the example above, I do a pwd, then list all files in the directory using ls, then finally change my directory with cd. Try doing that with IDLE.
Magic features
Another cool feature is that IPython comes with many magic features. These allow you to do things like change directories, which we saw above.
We can also run any Python script from within IPython using %run:
What if you want to run other system commands? Simple, run them by adding a ! to the front. Here is me getting info about my Windows system (by running Windows specific commands):
What if you want to see which variables you have defined?
Or embed your graphs directly within IPython:
There are hundreds of magic commands for everything and anything you could need.
IPython Notebook
The IPython Notebook is another feature that blows you out of the water the first time you use it. It’s power is that you can mix code with Markdown/Latex formatted code. Which means that if you write tutorials, you no longer have to switch between text and code (and neither do your students). Everything is in one place:
Let that sink in for a moment. You can read a tutorial, and run the code, right in the tutorial itself, without having to open another window/shell.
If you change your tutorial, your code gets automatically updated, as they are in the same place.
And not only that, you can share your IPython Notebook as a HTML, Markdown, Rst, and in newer versions, PDF as well.
The future
IPython has evolved into the Jupyter project, which takes IPython and extends it to other languages like R and Julia (for now).
I am waiting for the time when someone writes an entire book purely in IPython. There are a few problems at the moment, but if you know someone who has done this, or trying to do it, please let me know.
Updated based on reader feedback
Ipython can also be run in a pure shell mode. Thanks to Denilson and Simon for pointing that out.
And as Rachel Thomas points out, there are several books written in Ipython! Here is a selection.
Thank you for your feedback on IPython, I have been learning with IDLE and many of the complaints you have with it I share. I will be switching…now.
Thanks Jeremy.
Yes, IDLE should not be used by anyone…
There are entire books written in IPython!
https://github.com/ipython/ipython/wiki/A-gallery-of-interesting-IPython-Notebooks#entire-books-or-other-large-collections-of-notebooks-on-a-topic
That’s a great link! Thanks for sharing. It’ll go in the blog.
You mention two flavors of IPython: QT console and Notebook.
In fact, there is a third one: the pure console. Open a terminal and run “ipython” and you get the shell directly inside the terminal. Since it is text-only, there are no inline graphics. But it also means you can run the shell in remote servers through ssh.
By the way, IPython through a remote shell via ssh is the way https://www.python.org/shell/ works.
You also have a console shell if you just run “python” , but it is very limited when compared to ipython.
Thanks for the link!
Another big drawback of IDLE: no line numbers in the editor. If you run a program and get an error with a line number, too bad, you can’t use the line number to find it.
The other IDE’s I’ve looked at seem to be bloated monstrosities that might be great for professional software developers but are unsuited to beginners, or people who want to run short scripts. IDLE isn’t even good enough for beginners.
True about the bloated monstrosities. I’m looking at you, Eclipse.
Don’t forget the old console based interface. Makes for a powerful she’ll replacement on Windows with all thwbfeatures of the qt interface (-graphs in-line).
Yes. Denilson mentioned the same thing. Yes, I forgot about it!
For Mac users there is also a standalone frontend to IPython, called “Pineapple”.
https://nwhitehead.github.io/pineapple/
Thanks. That looks great!
Thanks. This is excellent information. I used IDLE for a while and liked it until I began using IPython. No comparison. Your article has opened up even more capabilities. Thanks! Jim
You are welcome Jim.
Awesome!
Thanks, very useful info. Note that the online shell you link to provides a (bare) Python shell, not iPython.
You are right. It did provide a link to iPython, but they must have changed it. I’ll remove the link. Thanks,