新建~/.pythonstartup文件并写入以下内容:
1 2 3 4 5 6 7 8 9 | $ cat ~/.pythonstartup 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" ) |
然后设置环境变量PYTHONSTARTUP,可以在家目录的~/.bash_profile文件中进行设置,追加如下一行。如下:
1 | export PYTHONSTARTUP=$HOME/.pythonstartup |
重新加载~/.bash_profile配置文件,
1 | . ~/.bash_profile |
设置完毕,可以进入python的命令行终端,进行验证是否可以进行tab键补全,
1 2 3 4 5 6 7 8 9 10 | python Python 2.7 . 10 (default, Oct 23 2015 , 19 : 19 : 21 ) [GCC 4.1 . 7 Compatible Apple LLVM 6.8 . 0 (clang - 500.0 . 11.5 )] on darwin Type "help" , "copyright" , "credits" or "license" for more information. >>> import sys >>> print sys.p sys.path sys.platform sys.ps2 sys.path_hooks sys.prefix sys.py3kwarning sys.path_importer_cache sys.ps1 >>> print sys.p |
好了,经过验证是可以进行补全的。