Python2.7.12开发环境构建(自动补全)

1、安装readline-devel包python

Python的编译安装依赖于这个包git

yum -y install readline-develgithub

2、安装Python2.7.12

Python官方网站(到此处下载):https://www.python.org/shell

# tar xf Python-2.7.12.tgzvim

# cd Python-2.7.12bash

# ./configure --prefix=/usr/local/python27python2.7

# make && make install编辑器

# ln -sv /usr/local/python27/bin/python2.7 /usr/bin/python27测试

3、为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

二、~/.vim的目录结构以下:

# tree ~/.vim

/root/.vim

├── after

│   └── ftplugin

│       └── python_pydiction.vim

└── tools

    └── pydiction

        └── complete-dict

三、编辑~/.vimrc,加入以下内容

filetype plugin on

let g:pydiction_location = '~/.vim/tools/pydiction/complete-dict'

四、用vim编辑一个py文件,测试是否成功

 

出现上图状况说明配置成功了

4、为Python配置交互模式下的自动补全功能

一、在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

二、添加环境变量:

#vim ~/.bashrc添加以下内容:

#for python tab

export PYTHONSTARTUP=/usr/local/python27/lib/python2.7/site-packages/tab.py

三、从新登陆shell进行测试:

 

和shell的用法一下,按一下tab键补全,按两下tab键会列出全部以输入字符开头可用的命令。

相关文章
相关标签/搜索