一、python添加TAB键
将以下代码保存到python库中,命名为 tab.
#vim tab.py #编辑模块
#!/usr/local/bin/python
#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 os,histfile,readline,rlcompleter
#mv tab.py /usr/local/lib/python2.7/ #移动tab模块到python模块默认路径下
>>> import sys
>>> sys.path #查看库默认存放路径
['', '/usr/local/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg', '/usr/local/lib/python2.7/site-packages/readline-6.2.4.1-py2.7-linux-x86_64.egg', '/usr/local/lib/python27.zip', '/usr/local/lib/python2.7', '/usr/local/lib/python2.7/plat-linux2', '/usr/local/lib/python2.7/lib-tk', '/usr/local/lib/python2.7/lib-old', '/usr/local/lib/python2.7/lib-dynload', '/usr/local/lib/python2.7/site-packages']
>>> import tab #导入TAB模块
>>> sys.
sys.__class__( sys.exit(
sys.__delattr__( sys.exitfunc(
sys.__dict__ sys.flags
sys.__displayhook__( sys.float_info
sys.__doc__ sys.float_repr_style
sys.__egginsert sys.getcheckinterval(
sys.__excepthook__( sys.getdefaultencoding(
sys.__format__( sys.getdlopenflags(
sys.__getattribute__( sys.getfilesystemencoding(
sys.__hash__( sys.getprofile(
sys.__init__( sys.getrecursionlimit(
sys.__name__ sys.getrefcount(
sys.__new__( sys.getsizeof(
二、新安装python2.7以上版本,导致Yum不能运行,找不到yum模块,因为yum是python程序写的。
执行yum报错信息:
# yum
There was a problem importing one of the Python modules
required to run yum. The error leading to this problem was:
No module named yum #找不到yum模块
Please install a package which provides this module, or
verify that the module is installed correctly.
It's possible that the above module doesn't match the
current version of Python, which is:
2.7.9 (default, Mar 11 2017, 19:17:43)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-17)]
If you cannot solve this problem yourself, please go to
the yum faq at:
http://yum.baseurl.org/wiki/Faq
编辑yum命令,修改头解释器为系统安装的python2.6版本。
查看python执行路径
# ll /usr/bin/py*
-rwxr-xr-x 2 root root 9032 Jan 22 2014 /usr/bin/python
lrwxrwxrwx. 1 root root 6 Mar 11 18:29 /usr/bin/python2 -> python
-rwxr-xr-x 2 root root 9032 Jan 22 2014 /usr/bin/python2.6
-rwxr-xr-x 2 root root 9032 Jan 22 2014 /usr/bin/python2.7
修改yum路径中python指向路径:
#vim /usr/bin/yum
#!/usr/bin/python #将此处改为python2.6路径(/usr/bin/python2.6)
import sys
try:
import yum
except ImportError:
print >> sys.stderr, """\
There was a problem importing one of the Python modules
required to run yum. The error leading to this problem was:
%s
Please install a package which provides this module, or
verify that the module is installed correctly.
It's possible that the above module doesn't match the
current version of Python, which is:
%s
If you cannot solve this problem yourself, please go to
the yum faq at:
http://yum.baseurl.org/wiki/Faq
""" % (sys.exc_value, sys.version)
sys.exit(1)
sys.path.insert(0, '/usr/share/yum-cli')
try:
import yummain
yummain.user_main(sys.argv[1:], exit_code=True)
except KeyboardInterrupt, e:
print >> sys.stderr, "\n\nExiting on user cancel."
sys.exit(1)