本文转载自 Centos6下Python3的编译安装
系统环境:CentOS 6.8-Minimal
安装Python依赖包:
1
|
[root@Python src] # yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gcc make
|
下载Python源码包:
1
|
[root@Python src] # wget http://mirrors.sohu.com/python/3.5.2/Python-3.5.2.tgz
|
编译、安装:
1
2
3
4
5
|
[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命令到环境变量:
1
2
3
4
5
|
[root@Python /] # vim ~/.bash_profile
PATH=$PATH:$HOME /bin
改为: PATH=$PATH:$HOME /bin : /usr/local/python/bin
|
使环境变量生效:
1
|
[root@Python /] # source ~/.bash_profile
|
查看Python版本:
1
2
|
[root@Python /] # python3 -V
Python 3.5.2 |
更改系统默认python版本为Python3.5
1
2
|
[root@Python /] # mv /usr/bin/python /usr/bin/python2.6
[root@Python /] # ln -s /usr/local/python/bin/python3.5 /usr/bin/python
|
核对Python版本:
1
2
|
[root@Python /] # python -V
Python 3.5.2 |
解决python升级后,YUM不能正常工作的问题:
1
|
#vi /usr/bin/yum |
将文件头部的 #!/usr/bin/python 改成 #!/usr/bin/python2.6