Centos6下Python3的编译安装

Python 3.5源码编译安装

 

系统环境:CentOS 6.8-Minimal

安装Python依赖包:

[root@Python src]# yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gcc make

下载Python源码包:

[root@Python src]# wget http://mirrors.sohu.com/python/3.5.2/Python-3.5.2.tgz

编译、安装:

[root@Python /]# tar -xzvf /usr/local/src/Python-3.5.2.tgz -C /usr/local/src/
[root@Python /]# cd /usr/local/src/Python-3.5.2
[root@Python Python-3.5.2]# ./configure --prefix=/usr/local/python
[root@Python Python-3.5.2]# make -j 4
[root@Python Python-3.5.2]# make install

查看扩展安装包:

[root@Python /]# /usr/local/python/bin/pip3 list pip (8.1.1) setuptools (20.10.1)

添加Python命令到环境变量:

[root@Python /]# vim ~/.bash_profile

PATH=$PATH:$HOME/bin
改为:
PATH=$PATH:$HOME/bin:/usr/local/python/bin

使环境变量生效:

[root@Python /]# source ~/.bash_profile

查看Python版本:

[root@Python /]# python3 -V
Python 3.5.2

更改系统默认python版本为Python3.5

[root@Python /]# mv /usr/bin/python /usr/bin/python2.6
[root@Python /]# ln -s /usr/local/python/bin/python3.5 /usr/bin/python

核对Python版本:

[root@Python /]# python -V
Python 3.5.2

解决python升级后,YUM不能正常工作的问题:

#vi /usr/bin/yum

  将文件头部的   #!/usr/bin/python   改成   #!/usr/bin/python2.6

 

[THE END]

posted @ 2017-03-24 05:50  SRE在路上  阅读(2754)  评论(0编辑  收藏  举报