如何在cenots6.5中安装Python3.4

linux系统(散仙的是centos6.5)自带的python的版本是2.6的,如果我们想使用新的python3.x怎么办,我们不需要卸载原来的python,在py的脚本文件里指定加载的python的路径即可。

默认的系统自带的python脚本如下所示:
[root@Slave2 ~]# py
pydoc             python            python2           python2.6         python2.6-config  python-config     
[root@Slave2 ~]# which python
/usr/bin/python
[root@Slave2 ~]# 


我们首先执行 yum  update python -y如果升级失败,则选择编译源码升级,yum升级的方式,一般都会失败,所以大家还是准备编译源码安装python3.4比较靠谱。


1,如果是centos的精简版的建议先安装一些依赖的相关包:
yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gcc make


2,然后下载python3.4的源码包
 wget https://www.python.org/ftp/python/3.4.0/Python-3.4.0.tgz

-rw-r--r-- 1 root root  19M 3月  17 2014 Python-3.4.0.tgz



3,解压到/usr/local/src下
tar xf Python-3.4.0.tgz -C /usr/local/src/


进入执行编译:
cd /usr/local/src/Python-3.4.0/
./configure --prefix=/usr/local/python3.4
make -j4 && make install


4,给python3.4添加环境变量:
PATH=$PATH:$HOME/bin:/usr/local/python3.4/bin


然后退出登录,再次查看python命令:
[root@master ~]# py
pydoc              pydoc3.4           python2            python3            python3.4-config   python3.4m-config  pyvenv             
pydoc3             python             python2.6          python3.4          python3.4m         python3-config     pyvenv-3.4         
[root@master ~]# py
pydoc              pydoc3.4           python2            python3            python3.4-config   python3.4m-config  pyvenv             
pydoc3             python             python2.6          python3.4          python3.4m         python3-config     pyvenv-3.4         
[root@master ~]# py



我们发现python3.4已经有了,原来的2.6也存在,我们可以选择执行那个版本的python:
[root@master ~]# python2
Python 2.6.6 (r266:84292, Nov 22 2013, 12:16:22) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()
[root@master ~]# python3
Python 3.4.0 (default, Sep 24 2014, 00:45:56) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-4)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()
[root@master ~]# 


执行我们的python3.4就安装成功了。

你可能感兴趣的:(linux,python)