1. python3用户需下载readline模块(pip isntall readline)
2. 创建文件~/.pythonstartup,内容如下# python startup file
import sys
import readline
import rlcompleter
import atexit
import os
# tab completion
readline.parse_and_bind('tab: complete')
# history file
histfile = os.path.join(os.environ['HOME'], '.pythonhistory')
try:
readline.read_history_file(histfile)
except IOError:
pass
atexit.register(readline.write_history_file, histfile)
del sys, os, histfile, readline, rlcompleter, atexit
3. 在~/.bash_profile中添加环境变量(只针对当前用户,若要对所有用户有效,需加入到/etc/profile)
4. export PYTHONSTARTUP=~/.pythonstartup
5. source ~/.bash_profile