import rlcompleter, readline, os atexit
readline.parse_and_bind('tab: complete')
history_file = os.path.expanduser('~/.python_history')
readline.read_history_file(history_file)
atexit.register(readline.write_history_file, history_file)
Note: install the readline package if it is not ready.
export PYTHONSTARTUP=~/.pythonrc
source ~/.zshrc (~/.bashrc for bash),or you can open a new shell