centos6.7安装python2.7.11的具体方法
1.查看本机系统及python版本
#cat/etc/redhat-release
CentOSrelease6.7(Final)
查看CentOSrelease6.7(Final)自带的python版本
#python-V
Python2.6.6
注意,我们不要破坏系统的Python环境,因为几个关键的实用应用程序依赖于系统默认的Python2.6.6,如果破坏了系统的Python环境就会发生很多难以预见的错误,导致要重装系统。
2.yum安装开发工具库集及一些额外包包
#yumgroupinstall"Developmenttools"
#yuminstallzlib-develbzip2-developenssl-develncurses-develsqlite-develreadline-develtk-devel
3.下载并解压python2.7.11源码包
#wget-c--no-check-certificatehttps://www.python.org/ftp/python/2.7.11/Python-2.7.11.tar.xz
#tarxfPython-2.7.11.tar.xz
#cdPython-2.7.11
4.编译并安装python2.7.11
#./configure--prefix=/usr/local
#make&&makealtinstall
其中,./configure--prefix=是指定安装路径,按照官方文档,如果要将多个Python运行时安装在同一目录,则使用makealtinstall而不是makeinstall
(注意:不指定prefix,则可执行文件默认放在/usr/local/bin,库文件默认放在/usr/local/lib,配置文件默认放在/usr/local/etc。其它的资源文件放在/usr/local/share。你要卸载这个程序,要么在原来的make目录下用一次makeuninstall(前提是make文件指定过uninstall),要么去上述目录里面把相关的文件一个个手工删掉。
指定prefix,直接删掉一个文件夹就够了)
5.为python2.7执行文件创建软链接
#ln-s/usr/local/bin/python2.7/usr/local/bin/python
将/usr/local/bin/python指向/usr/local/bin/python2.7
6.检测python版本
#sh
sh-4.1#python-V
Python2.7.11
sh-4.1#exit
exit
#python
Python2.6.6(r266:84292,Jul232015,15:22:56)
[GCC4.4.720120313(RedHat4.4.7-11)]onlinux2
Type"help","copyright","credits"or"license"formoreinformation.
>>>
我们发现,在sh下检测到Python的版本是2.7.11,但终端下仍然是默认的2.6.6,这是因为要重启终端才生效,我们重启终端后:
#python
Python2.7.11(default,Feb242016,09:50:38)
[GCC4.4.720120313(RedHat4.4.7-16)]onlinux2
Type"help","copyright","credits"or"license"formoreinformation.
>>>
python版本默认是我们新安装的Python2.7.11,这是因为在环境变量PATH中/usr/local/bin在/usr/bin前面,其优先级高:
#echo$PATH
/usr/local/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/java/jdk1.8.0_60/bin:/root/bin
或看看当前使用的是哪个python:
#whichpython
/usr/local/bin/python
查看python路径:
#whereispython
python:/usr/bin/python2.6/usr/bin/python/usr/lib/python2.6/usr/lib64/python2.6/usr/local/bin/python/usr/local/bin/python2.7-config/usr/local/bin/python2.7/usr/local/lib/python2.7/usr/include/python2.6/usr/share/man/man1/python.1.gz7.解决DeleteBackspace方向键不能用问题
若发现,在python命令行下,DeleteBackspace方向键不能用问题,情况如下:
#python
Python2.7.11(default,Feb242016,09:50:38)
[GCC4.4.720120313(RedHat4.4.7-16)]onlinux2
Type"help","copyright","credits"or"license"formoreinformation.
>>>ex^[[D^[[D^[[C^[[C^[[C^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^[[3~^[[3~^[[3~^C
这是因为在编译安装python前,没有安装readline-devel所致。
解决方法是先安装readline-devel,再回到源码包路径下,重新执行命令安装,即可解决,如下:
#yuminstallreadline-devel
#cdPython-2.7.11
#make&&makealtinstall
到此,我们完成了centos6.7下python2.7.11的安装!
OK,Enjoyit!!!
以上这篇centos6.7安装python2.7.11的具体方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持毛票票。