首页 > 代码库 > python--linux安装

python--linux安装

centos7

查看默认Python版本自带2.7.5版本

[root@linux-node1 ~]# cat /etc/redhat-releaseCentOS Linux release 7.3.1611 (Core)[root@linux-node1 ~]# python -VPython 2.7.5

升级版本-3.x

1、安装gcc,用于编译Python源码

[root@linux-node1 ~]# yum install gcc

 2、下载源码包

 官网下载:https://www.python.org/ftp/python/

3、解压并进入源码文件

[root@linux-node1 ~]# lltotal 14468-rw-------. 1 root root     1208 Dec 15  2016 anaconda-ks.cfg-rw-r--r--  1 root root 14808460 Apr 20 15:47 Python-3.5.0.tar.xz[root@linux-node1 ~]# tar xf Python-3.5.0.tar.xz[root@linux-node1 ~]# cd Python-3.5.0/[root@linux-node1 Python-3.5.0]# lltotal 980-rw-r--r--  1 1000 1000   8466 Sep 13  2015 aclocal.m4-rwxr-xr-x  1 1000 1000  42856 Sep 13  2015 config.guess-rwxr-xr-x  1 1000 1000  35740 Sep 13  2015 config.sub-rwxr-xr-x  1 1000 1000 464952 Sep 13  2015 configure-rw-r--r--  1 1000 1000 150676 Sep 13  2015 configure.acdrwxrwxr-x 18 1000 1000   4096 Sep 13  2015 Docdrwxrwxr-x  2 1000 1000     20 Sep 13  2015 Grammardrwxrwxr-x  2 1000 1000   4096 Sep 13  2015 Include-rwxr-xr-x  1 1000 1000   7122 Sep 13  2015 install-shdrwxrwxr-x 46 1000 1000   8192 Sep 13  2015 Lib-rw-r--r--  1 1000 1000  12761 Sep 13  2015 LICENSEdrwxrwxr-x  8 1000 1000    151 Sep 13  2015 Mac-rw-r--r--  1 1000 1000  56690 Sep 13  2015 Makefile.pre.indrwxrwxr-x  2 1000 1000   4096 Sep 13  2015 Miscdrwxrwxr-x 11 1000 1000   4096 Sep 13  2015 Modulesdrwxrwxr-x  4 1000 1000   4096 Sep 13  2015 Objectsdrwxrwxr-x  2 1000 1000   4096 Sep 13  2015 Parserdrwxrwxr-x  6 1000 1000   4096 Sep 13  2015 PCdrwxrwxr-x  2 1000 1000   4096 Sep 13  2015 PCbuilddrwxrwxr-x  2 1000 1000     79 Sep 13  2015 Programs-rw-r--r--  1 1000 1000  41790 Sep 13  2015 pyconfig.h.indrwxrwxr-x  3 1000 1000   4096 Sep 13  2015 Python-rw-r--r--  1 1000 1000   6740 Sep 13  2015 README-rw-r--r--  1 1000 1000  98075 Sep 13  2015 setup.pydrwxrwxr-x 22 1000 1000   4096 Sep 13  2015 Tools

4、编译安装

[root@linux-node1 Python-3.5.0]# ./configure[root@linux-node1 Python-3.5.0]# make all[root@linux-node1 Python-3.5.0]# make install

注:编译需要等一段时间~

5、查看版本

[root@linux-node1 Python-3.5.0]# /usr/local/bin/python3.5 -VPython 3.5.0

6、修改默认Python版本

[root@linux-node1 Python-3.5.0]# mv /usr/bin/python /usr/bin/python2.7.5         #移走旧版本的python并命名为2.7.5[root@linux-node1 Python-3.5.0]# ln -s /usr/local/bin/python3.5 /usr/bin/python  #做软连接[root@linux-node1 Python-3.5.0]# python -V                                       #验证默认版本 Python 3.5.0

 

7、防止yum执行异常,修改yum使用的Python版本

[root@linux-node1 Python-3.5.0]# vim /usr/bin/yum    #将头部 #!/usr/bin/python 修改为 #!/usr/bin/python3.5[root@linux-node1 Python-3.5.0]# cat /usr/bin/yum#!/usr/bin/python3.5import sys

 

python--linux安装