设置python中TAB键自动补全方法
linux服务器上:###########################################################################
一、创建自动补全脚本如下:
vi /tmp/python/tab.py
#!/usr/bin/python
# python tab 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
二、导入上面创建的模块
-----------------方法一:
#python
>>>import sys
>>>sys.path.append('/tmp/python/')
>>>import tab
----------------方法二:
cp /tmp/python/tab.py /usr/lib/python2.6/site-packages
#python
>>>import tab
#至此便可利用TAB补全了
#########################################################################
ipython也有tab自动补全功能,安装方法如下:
tar -zxvf ipython-0.12.tar.gz
cd ipython-0.12
python setup.py install
ipython
#注:在ipython中使用!加命令九如同在shell中一样,如!init 0
windows服务器上:###########################################################################
1、安装Python后将C:\Python27和C:\Python27\Scripts加入系统环境变量path中
2、安装pyreadline,方法如下:
pip.exe install pyreadline 或者easy_install pyreadline
3、在C:\Python27\Lib\site-packages新建tab.py,内容如下
#!/usr/bin/python
# python tab 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['HOMEPATH'], '.pythonhistory')
try:
readline.read_history_file(histfile)
except IOError:
pass
atexit.register(readline.write_history_file, histfile)
del os, histfile, readline, rlcompleter
####################################################################
在一个系统中共存Python2、python3的时候,pip、pip2、pip3使用的时候会报错:
c:\Python36\Scripts>pip3
Fatal error in launcher: Unable to create process using '"'
解决方法:
python3:
python3 -m pip install --upgrade pip
python2:
python2 -m pip install --upgrade pip
注意:python2, python3共存时,将python安装目录下的python.exe改成对应的python2.exe,python3.exe
python3 -m pip pyreadline或者python3 -m easy_install pyreadline