本文共 2729 字,大约阅读时间需要 9 分钟。
Linux下默认系统自带python2.6的版本,这个版本被系统很多程序所依赖,所以不建议删除,如果使用最新的Python3那么我们知道编译安装源码包和系统默认包之间是没有任何影响的,所以可以安装python3和python2共存
首先去python官网下载python3的源码包,网址:
进去之后点击导航栏的Downloads,也可以鼠标放到Downloads上弹出菜单选择Source code,就是源码包的意思,点进去之后页面下方可以看到下载链接,包括源码包、Mac OSX安装包、Windows的安装包
[root@node1 ~]# yum install wget gcc automake autoconf zlib-devel libtool bzip2-devel openssl-devel xz -y[root@node1 ~]# yum install readline-devel.x86_64 #解决python3退格功能
拓展:
[root@node1 ~]# yum install tkinter tk-devel tk -y # 在Linux中python默认是不安装Tkinter模块,matplotlib依赖Tkinter模块,安装tensorflow需要;
[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 ~]# ./configure --enable-unicode=ucs2 --enable-shared // --enable-optimizations # 二者装一个就行,这个是多装一个Tkinter模块[root@node1 ~]# make && make install
[root@node1 ~]# python --versionPython 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/pythonlrwxrwxrwx 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 --versionPython 3.6.5
[root@node1 ~]# vim /usr/bin/yum1 #!/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/python3lrwxrwxrwx 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:
转载于:https://blog.51cto.com/moerjinrong/2125630