Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I often use Python 3000's interactive interpreter, but it's missing the convenience of tab-completion I'm used to from ipython, which isn't available for Python 3.x.

How do I enable tab completion in all of them, 2.6 and 3.x?

share|improve this question
up vote 15 down vote accepted

First, create a new file called in your home directory. Put the following script in it:

    import readline
except ImportError:
    print("Module readline not available.")
    import rlcompleter
    readline.parse_and_bind("tab: complete")

The parentheses around the string ensure that it works with both Python 2 and Python 3.

Every time the interactive interpreter is started, it executes a script defined in $PYTHONSTARTUP, if there is one. To set it to execute the above script, type


You should write this line to your .bashrc or .bash_profile file, so that it's automatically executed when a new shell is started.

share|improve this answer
NOTICE: This won't work if you start the terminal and then change directory. If you want this method to work no matter the directory you are, you should use the full path like export PYTHONSTARTUP="/home/user/" – Pithikos Oct 15 '14 at 14:58
Your can make the export a bit more tolerant by having export PYTHONSTARTUP=~/ – Mikael Fremling Jan 26 at 13:50

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.