标签:源码安装python
Linux下默认系统自带python2.6的版本,这个版本被系统很多程序所依赖,所以不建议删除,如果使用最新的Python3那么我们知道编译安装源码包和系统默认包之间是没有任何影响的,所以可以安装python3和python2共存首先去python官网下载python3的源码包,网址:https://www.python.org/
进去之后点击导航栏的Downloads,也可以鼠标放到Downloads上弹出菜单选择Source code,就是源码包的意思,点进去之后页面下方可以看到下载链接,包括源码包、Mac OSX安装包、Windows的安装包
[root@node1 ~]# yum -y install wget gcc automake zlib-devel openssl-devel xz
[root@node1 ~]# yum install readline-devel.x86_64 #解决python3退格功能
[root@node1 ~]# wget https://www.python.org/ftp/python/3.6.5/Python-3.6.5.tar.xz
[root@node1 ~]# tar xf Python-3.6.5.tar.xz && cd Python-3.6.5
[root@node1 ~]# ./configure
[root@node1 ~]# make && make install
[root@node1 ~]# python --version
Python 2.6.6
[root@node1 ~]# which python
/usr/bin/python
[root@node1 ~]# which python3
/usr/local/bin/python3
[root@node1 ~]# ll /usr/bin/python*
-rwxr-xr-x 2 root root 9728 8月 18 2016 /usr/bin/python
lrwxrwxrwx 1 root root 6 12月 11 14:14 /usr/bin/python2 -> python
-rwxr-xr-x 2 root root 9728 8月 18 2016 /usr/bin/python2.6
[root@node1 ~]# rm -f /usr/bin/python /usr/bin/python2
[root@node1 ~]# ln -s /usr/local/bin/python3 /usr/bin/python
[root@node1 ~]# ln -s /usr/bin/python2.6 /usr/bin/python2
验证:
[root@node1 ~]# python --version
Python 3.6.5
[root@node1 ~]# vim ?/usr/bin/yum
1 #!/usr/bin/python
改为
1 #!/usr/bin/python2.6 # 改为python默认版本,CentOS 7.*为python2.7
[root@node1 ~]# ansible all -m shell -a "sed -i ‘1s#python$#python2.6#g‘ /usr/bin/yum“
[root@node1 ~]# ansible all -m shell -a "head -1 /usr/bin/yum”
[root@node1 ~]# ll /usr/bin/python*
lrwxrwxrwx 1 root root 22 1月 4 09:41 /usr/bin/python -> /usr/local/bin/python3
lrwxrwxrwx 1 root root 18 1月 4 09:41 /usr/bin/python2 -> /usr/bin/python2.6
-rwxr-xr-x 1 root root 9728 8月 18 2016 /usr/bin/python2.6
[root@node1 ~]#
[root@node1 ~]# ansible all -m shell -a "sed -i ‘1s#python$#python2.7#g‘ /usr/libexec/urlgrabber-ext-down"
[root@node1 ~]# ansible all -m shell -a "head -1 /usr/libexec/urlgrabber-ext-down"
[root@node1 ~]# ansible all -m shell -a "sed -i ‘1s#python$#python2.7#g‘ /usr/bin/yum-config-manager"
[root@node1 ~]# ansible all -m shell -a "head -1 /usr/bin/yum-config-manager"
mv /usr/local/lib/{,bak_}libisl.so.10.1.1-gdb.py
提示:Ignoring ensurepip failure: pip 7.1.2 requires SSL/TLS
这是原因没有安装或升级openssl:
标签:源码安装python
原文地址:http://blog.51cto.com/moerjinrong/2125630