最近开始研究python,参考的是李杰老师的视频,由于视频中用的是2.7.X的版本,而我在自己机器上python -V查看后发现是2.6.6的,于是要做的当然就是自己再编译一个了
wget https://www.python.org/ftp/python/2.7.5/Python-2.7.5.tar.bz2 bunzip2 Python-2.7.5.tar.bz2 tar xvf Python-2.7.5.tar mkdir /usr/local/python27 cd Python-2.7.5 ./configure --prefix=/usr/local/python27 make && make install mv /usr/bin/python /usr/bin/python2.6.6 ln -s /usr/local/python27/bin/python /usr/bin/python
至此为止还并未遇到问题,然而已经埋下伏笔;接下来因为python不自带tab补齐所以当然要添加啦,不然多不方便是不是
vim ~/.pythonconf
然后写入
# 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)
随后把这份配置加入root的环境变量中
vim ~/.bashrc
写入
PYTHONSTARTUP=~/.pythonconf export PYTHONSTARTUP
重新加载配置
source ~/.bashrc
此时进入pyhon,发现并不能tab补齐,并且出现以下报错:
ImportError: No module named readline
这是缺少readline模块了?好吧再装就是了,结果发现yum竟然挂了
查询一番以后发现是yum和python之间的依赖关系导致的,按照查到的方法继续
whereis python python: /usr/bin/python2.6 /usr/bin/python /usr/lib/python2.6 /usr/lib64/python2.6 /usr/include/python2.6 /usr/share/man/man1/python.1.gz
将yum改到原来的python2.6上
vim /usr/bin/yum
将路径解释的#!/usr/bin/python改成
#!/usr/bin/python2.6
至此,yum问题终于解决,那么剩下来就是readline了
yum install readline-devel*
删掉之前残缺的python
cd /usr/local/python27/ rm -rf *
最后按照上面做过的重新编译安装python2.7.5即可
进入python后tab补齐功能终于出现
原文:http://499825665.blog.51cto.com/5172595/1730725