码迷,mamicode.com
首页 > 编程语言 > 详细

python--linux安装

时间:2017-08-08 23:08:37      阅读:275      评论:0      收藏:0      [点我收藏+]

标签:span   升级版本   nod   efi   sep   strong   misc   value   linu   

centos7

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

[root@linux-node1 ~]# cat /etc/redhat-release
CentOS Linux release 7.3.1611 (Core)
[root@linux-node1 ~]# python -V
Python 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 ~]# ll
total 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]# ll
total 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.ac
drwxrwxr-x 18 1000 1000   4096 Sep 13  2015 Doc
drwxrwxr-x  2 1000 1000     20 Sep 13  2015 Grammar
drwxrwxr-x  2 1000 1000   4096 Sep 13  2015 Include
-rwxr-xr-x  1 1000 1000   7122 Sep 13  2015 install-sh
drwxrwxr-x 46 1000 1000   8192 Sep 13  2015 Lib
-rw-r--r--  1 1000 1000  12761 Sep 13  2015 LICENSE
drwxrwxr-x  8 1000 1000    151 Sep 13  2015 Mac
-rw-r--r--  1 1000 1000  56690 Sep 13  2015 Makefile.pre.in
drwxrwxr-x  2 1000 1000   4096 Sep 13  2015 Misc
drwxrwxr-x 11 1000 1000   4096 Sep 13  2015 Modules
drwxrwxr-x  4 1000 1000   4096 Sep 13  2015 Objects
drwxrwxr-x  2 1000 1000   4096 Sep 13  2015 Parser
drwxrwxr-x  6 1000 1000   4096 Sep 13  2015 PC
drwxrwxr-x  2 1000 1000   4096 Sep 13  2015 PCbuild
drwxrwxr-x  2 1000 1000     79 Sep 13  2015 Programs
-rw-r--r--  1 1000 1000  41790 Sep 13  2015 pyconfig.h.in
drwxrwxr-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.py
drwxrwxr-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 -V
Python 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.5
import sys

 

python--linux安装

标签:span   升级版本   nod   efi   sep   strong   misc   value   linu   

原文地址:http://www.cnblogs.com/syaving/p/7309178.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!