首先新建一个tab.py文件

duwens-MacBook-Air:~ duwen$ cd /Library/Python/2.7/site-packages/
duwens-MacBook-Air:site-packages duwen$ sudo touch tab.py
Password:
duwens-MacBook-Air:site-packages duwen$ vim tab.py 
duwens-MacBook-Air:site-packages duwen$ sudo vim tab.py 

内容是:

import sys
import readline
import rlcompleter

if sys.platform == 'darwin' and sys.version_info[0] == 2:
    readline.parse_and_bind("bind ^I rl_complete")
else:
    readline.parse_and_bind("tab: complete")

设置好环境变量,并编译

duwens-MacBook-Air:~ duwen$ vim ~/.bash_profile 
duwens-MacBook-Air:~ duwen$ source ~/.bash_profile

添加的内容是

export PYTHONSTARTUP=/Library/Python/2.7/site-packages/tab.py