Archive
Add History and Tab Completion to the Default Python Shell
Problem
You want history and TAB completion in your default Python shell. You are aware of bpython and ipython, but you miss this functionality in the default shell.
Solution
Edit ~/.bashrc:
# ~/.bashrc export PYTHONSTARTUP=$HOME/.pythonstartup.py
Download pythonstartup.py from here and rename it to ~/.pythonstartup.py.
IPython for Windows
Installation instructions: http://ipython.org/ipython-doc/stable/install/install.html#windows.
The important thing is to install IPython as administrator. This way Start menu shortcuts will be created and you can launch IPython easily. The IPython shortcut calls ‘C:\Python27\python.exe “C:\Python27\scripts\ipython-script.py”‘ in my case and I don’t want to type all that each time I want to launch IPython :)
ipython notebook
IPython notebook can be installed the following way on Ubuntu:
sudo pip install ipython -U sudo pip install tornado sudo apt-get install libzmq-dev sudo apt-get install python2.7-dev sudo pip install pyzmq
Execution:
ipython notebook
Update (20120418)
To learn more about IPython, check out this monstre tutorial (more than 3 hours long :))
the bpython interpreter
“bpython is a fancy interface to the Python interpreter for Unix-like operating systems (I hear it works fine on OS X). It is released under the MIT License. It has the following features:
- In-line syntax highlighting.
- Readline-like autocomplete with suggestions displayed as you type.
- Expected parameter list for any Python function.
- “Rewind” function to pop the last line of code from memory and re-evaluate.
- Send the code you’ve entered off to a pastebin.
- Save the code you’ve entered to a file.
- Auto-indentation.
- Python 3 support.
For more, see our about-page or just skip right to the screenshots.”
Installation
sudo apt-get install bpython
Tip: add the following line to your ~/.bashrc file:
alias bpy='bpython'
Then you can start the bpython interpreter with “p“. Short and simple :)
Alternatives
- classic “python” interpreter
- ipython
IPython, an enhanced Python shell
“IPython is an interactive shell for the Python programming language that offers enhanced introspection, additional shell syntax, syntax highlighting, tab completion and rich history. It is a component of the SciPy package.” (source)
Links:
- FrontPage – IPython (the HQ)
- IPython: A System for Interactive Scientific Computing (article, PDF)
- Cookbook – IPython
- IPython mailing list
In the book Python for Unix and Linux System Administration, there is a long chapter (Ch. 2) dedicated to IPython!
Installation and usage
Install it via apt-get:
sudo apt-get install ipython
I made the alias “ip” for the command “ipython”. Note that there is a command “ip” for manipulating routing and tunnels that the alias will hide, but it’s not likely I’ll ever use that command.
alias ip='ipython'
The config file of IPython is located at ~/.ipython/ipy_user_conf.py.
