設置python中TAB鍵自動補全方法python
linux服務器上:###########################################################################linux
1、建立自動補全腳本以下:shell
vi /tmp/python/tab.pywindows
#!/usr/bin/python服務器
# python tab file app
import syside
import readlinespa
import rlcompleterorm
import atexitip
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、導入上面建立的模塊
-----------------方法一:
#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服務器上:###########################################################################
一、安裝Python後將C:\Python27和C:\Python27\Scripts加入系統環境變量path中
二、安裝pyreadline,方法以下:
pip.exe install pyreadline 或者easy_install pyreadline
三、在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
####################################################################
在一個系統中共存Python二、python3的時候,pip、pip二、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