#创建存放Python安装包的位置:

mkdir -p /home/www/tools

cd /home/www/tools

#下载安装包Python-2.7.20.tar.gz

wget https://www.python.org/ftp/python/2.7.10/Python-2.7.10.tgz

tar xf Python-2.7.10.tar.gz

cd Python-2.7.10

./configure && make && make install


#修改版本连接

mv /usr/bin/python /usr/bin/python2.6

ln -s /usr/local/bin/python2.7 /usr/bin/python 

[root@Python ~]# python -V

Python 2.7.10


因为Python默认没有tab键功能

这里我们手动写一个,内容如下:

try:

    import readline

except ImportError:

    print("Module readline not available.")

else:

    import rlcompleter

    readline.parse_and_bind("tab: complete")


将以上内容保存在用户的家目录下.startup.py(名字可以随便去,只要不跟系统关键字冲突即可),这里我们放在/root/.startup.py,然后在/root/.bash_profile中申明一个变量PYTHONSTARTUP=~/.startup.py


[root@Python ~]# cat .bash_profile 

# .bash_profile


# Get the aliases and functions

if [ -f ~/.bashrc ]; then

        . ~/.bashrc

fi


# User specific environment and startup programs


PATH=$PATH:$HOME/bin


export  PYTHONSTARTUP=~/.pythonrc.py

然后退出登录,重新登录切换到Python环境下导入sys模块测试tab键


[root@Python ~]# python

Python 2.7.10 (default, Nov  2 2015, 14:32:17) 

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

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

>>> import sys

>>> sys.

sys.__class__(              sys.__reduce_ex__(          sys.argv                    sys.exit(                   sys.long_info               sys.setcheckinterval(

sys.__delattr__(            sys.__repr__(               sys.builtin_module_names    sys.flags                   sys.maxint                  sys.setdlopenflags(

sys.__dict__                sys.__setattr__(            sys.byteorder               sys.float_info              sys.maxsize                 sys.setprofile(

sys.__displayhook__(        sys.__sizeof__(             sys.call_tracing(           sys.float_repr_style        sys.maxunicode              sys.setrecursionlimit(

sys.__doc__                 sys.__stderr__              sys.callstats(              sys.getcheckinterval(       sys.meta_path               sys.settrace(

sys.__excepthook__(         sys.__stdin__               sys.copyright               sys.getdefaultencoding(     sys.modules                 sys.stderr

sys.__format__(             sys.__stdout__              sys.displayhook(            sys.getdlopenflags(         sys.path                    sys.stdin

sys.__getattribute__(       sys.__str__(                sys.dont_write_bytecode     sys.getfilesystemencoding(  sys.path_hooks              sys.stdout

sys.__hash__(               sys.__subclasshook__(       sys.exc_clear(              sys.getprofile(             sys.path_importer_cache     sys.subversion

sys.__init__(               sys._clear_type_cache(      sys.exc_info(               sys.getrecursionlimit(      sys.platform                sys.version

sys.__name__                sys._current_frames(        sys.exc_type                sys.getrefcount(            sys.prefix                  sys.version_info

sys.__new__(                sys._getframe(              sys.excepthook(             sys.getsizeof(              sys.ps1                     sys.warnoptions

sys.__package__             sys._mercurial              sys.exec_prefix             sys.gettrace(               sys.ps2                     

sys.__reduce__(             sys.api_version             sys.executable              sys.hexversion              sys.py3kwarning             

>>> sys.