centos系统下需要使用tab键补全

在/usr/local/lib/python2.7/site-packages/目录下编写一个tab.py 文件


文件内容:

#!/usr/bin/python#pythonstartupfileimportsysimportreadlineimportrlcompleterimportatexitimportos#tabcompletionreadline.parse_and_bind('tab:complete')#historyfilehistfile=os.path.join(os.environ['HOME'],'.pythonhistory')try:readline.read_history_file(histfile)exceptIOError:passatexit.register(readline.write_history_file,histfile)delos,histfile,readline,rlcompleter


然后导入tab模块

[root@omserver ~]# python

Python 2.7 (r27:82500, Mar 18 2016, 13:43:18)

[GCC 4.4.7 20120313 (Red Hat 4.4.7-16)] on linux2

Type "help", "copyright", "credits" or "license" for more information.

>>> import tab

>>>import os

>>> os. (按tab键)

Display all 238 possibilities? (y or n)

os.EX_CANTCREAT os.WEXITSTATUS( os.chroot( os.getresgid( os.setpgid(

os.EX_CONFIG os.WIFCONTINUED( os.close( os.getresuid( os.setpgrp(

os.EX_DATAERR os.WIFEXITED( os.closerange( os.getsid( os.setregid(

os.EX_IOERR os.WIFSIGNALED( os.confstr( os.getuid( os.setresgid(

os.EX_NOHOST os.WIFSTOPPED( os.confstr_names os.initgroups( os.setresuid(

os.EX_NOINPUT os.WNOHANG os.ctermid( os.isatty( os.setreuid(

os.EX_NOPERM os.WSTOPSIG( os.curdir os.kill( os.setsid(

os.EX_NOUSER os.WTERMSIG(

........

如果在导入tab模块的时候报

ImportError: No module named readline


wget https://pypi.python.org/packages/source/r/readline/readline-6.2.1.tar.gz#md5=9604527863378512247fcaf938100797 --no-check-certificate

tar -zxvf readline-6.2.1.tar.gz

cd readline-6.2.1

python setup.py install

如果在编译安装的过程中出现如下错误:

/usr/bin/ld: cannot find -lncurses

collect2: ld returned 1 exit status

error: command 'gcc' failed with exit status 1

需要安装:

yum -y install gcc

找到libncurses.so

[root@omserver lib]# locate libncurses.so

/lib64/libncurses.so.5

/lib64/libncurses.so.5.7

然后

[root@omserver lib64]# cd /usr/local/lib

[root@omserver lib]# ln -sv /lib64/libncurses.so.5.7 libncurses.so

再重新编译安装

[root@omserver xmxu]# cd readline-6.2.1

[root@omserver readline-6.2.1]# python setup.py install