centos7安装python3

下载python3.5.2   

  wget http://mirrors.sohu.com/python/3.5.2/Python-3.5.2.tgz

  如果提示错误可能是wget没有安装,用yun -y install wget安装

 

安装前的准备

安装readline-devel,否则运行Python3.5.2后按删除键、方向键等键出现乱码

  yum install readline-devel

如果安装过程提示

Downloading packages:  

File "/usr/libexec/urlgrabber-ext-down", line 28    

    except OSError, e:                  

         ^ SyntaxError: invalid syntax

错误说明python解释器不对,编辑/usr/libexec/urlgrabber-ext-down,将第一行的python解释器(#! /usr/bin/python)换成centos自带的python2.7.5(#! /usr/bin/python2.7.5)即可。

 

安装  

  1、解压Python 3.4.3

    tar -xf Python-3.4.3.tgz 

  2、进入目录:

     cd Python-3.4.3/

  3、安装Python 3.4.3

    a、配置./configure

    b、编译make

    c、安装make install

如果配置./configure过程中提示

checking for gcc... no

checking for cc... no

checking for cl.exe... no

configure: error: in `/usr/Python-3.5.2':

configure: error: no acceptable C compiler found in $PATH See `config.log' for more details

的错误,可能是gcc-c++没有安装,使用命令yun install -y gcc-c++  后再重新安装即可

将python3.5.2设置成系统默认

上面我们已经将Python 3.5.2安装完成,但是我们进入shell后,查看python版本号: python -V,发现python还是2.7.5版本。

先将原来的python软连接重名

  mv /usr/bin/python /usr/bin/python2.7.5

编辑下yum的配置文件

  vi /usr/bin/yum将首行的#! /usr/bin/python改成#! /usr/bin/python2.7.5

我们建立一个新的链接

  ln -s /usr/local/bin/python3 /usr/bin/python

  注:最好先到/usr/local/bin/看下python的文件名是不是python3

检验python指向是否成功

  python -V

原文地址:https://www.cnblogs.com/liyang0519/p/6241973.html