Python2.7.12开发环境构建(自动补全)
一、安装readline-devel包
Python的编译安装依赖于这个包
yum -y install readline-devel
二、安装Python2.7.12
Python官方网站(到此处下载):https://www.python.org/
# tar xf Python-2.7.12.tgz
# cd Python-2.7.12
# ./configure --prefix=/usr/local/python27
# make && make install
# ln -sv /usr/local/python27/bin/python2.7 /usr/bin/python27
三、为vim编辑器添加Python自动补全功能
1、下载Python自动补全插件:pydiction
wget https://github.com/rkulla/pydiction/archive/master.zip
# unzip -q master
# mv pydiction-master pydiction
# mkdir -p ~/.vim/tools/pydiction
# cp -r pydiction/after ~/.vim
# cp pydiction/complete-dict ~/.vim/tools/pydiction
2、~/.vim的目录结构如下:
# tree ~/.vim
/root/.vim
├── after
│ └── ftplugin
│ └── python_pydiction.vim
└── tools
└── pydiction
└── complete-dict
3、编辑~/.vimrc,加入如下内容
filetype plugin on
let g:pydiction_location = '~/.vim/tools/pydiction/complete-dict'
4、用vim编辑一个py文件,测试是否成功
出现上图情况说明配置成功了
四、为Python配置交互模式下的自动补全功能
1、在Python的安装目录下/usr/local/python27/lib/python2.7/site-packages添加tab.py文件
tab文件内容如下:
#!/usr/bin/env python27
# 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
2、添加环境变量:
#vim ~/.bashrc添加如下内容:
#for python tab
export PYTHONSTARTUP=/usr/local/python27/lib/python2.7/site-packages/tab.py
3、重新登录shell进行测试:
和shell的用法一下,按一下tab键补全,按两下tab键会列出所有以输入字符开头可用的命令。