您的位置:首页 > 运维架构 > Linux

将linux默认python升级到2.7.4版本

2015-09-01 15:31 465 查看


将linux默认python升级到2.7.4版本

(2013-05-25 23:21:09)


转载▼

标签:


linux


python


升级


centos


python2.7

分类: python
第一步:下载python2.7.4版本源码:

wget http://python.org/ftp/python/2.7.4/Python-2.7.4.tgz

解压文件

[aa@localhost ~]$ tar jxvf Python-2.7.4.tar.bz2

[niuxl@localhost ~]$ cd Python-2.7.4

[niuxl@localhost Python-2.7.4]$ ls

config.guess configure Demo Grammar install-sh LICENSE Makefile.pre.in Modules Parser PCbuild Python RISCOS Tools

config.sub configure.ac Doc Include Lib Mac Misc Objects PC pyconfig.h.in README setup.py

[niuxl@localhost Python-2.7.4]$ su -

口令:

[root@localhost ~]# mkdir /usr/local/python2.7.4

[root@localhost ~]# cd /home/

[root@localhost home]# cd niuxl/Python-2.7.4

[root@localhost Python-2.7.4]# ls

config.guess configure Demo Grammar install-sh LICENSE Makefile.pre.in Modules Parser PCbuild Python RISCOS Tools

config.sub configure.ac Doc Include Lib Mac Misc Objects PC pyconfig.h.in README setup.py

编译之前,需要先安装zlib包:

[root@localhost Python-2.7.4]# yum install zlib zlib-devel

[root@localhost Python-2.7.4]# ./configure --prefix=/usr/local/python2.7.4

checking build system type... i686-pc-linux-gnu

checking host system type... i686-pc-linux-gnu

checking for--enable-universalsdk... no

checking for--with-universal-archs... 32-bit

checking MACHDEP... linux2

checking EXTRAPLATDIR...

checking for--without-gcc... no

checking forgcc... no

checking forcc... no

checking forcl.exe... no

configure: error: in `/home/niuxl/Python-2.7.4':

configure: error: no acceptable C compiler found in $PATH

缺少c编辑器

安装c编辑器:

[root@localhost Python-2.7.4]# yum install gcc

..略

注:有一个选择y和n的地方,提示是否继续下载,输入y,回车即可!

gcc安装完成

继续编译python
[root@localhost Python-2.7.4]# ./configure --prefix=/usr/local/python2.7.4

..(略)

ok编译成功

[root@localhost Python-2.7.4]# make && make install

安装成功

[root@localhost Python-2.7.4]# python -V

Python 2.4.3

目前版本依然是2.4.3,现在开始升级python,

查看python命令所在目录

[root@localhost Python-2.7.4]# whereis python

python: /usr/bin/python2.4 /usr/bin/python /usr/lib/python2.4 /usr/include/python2.4 /usr/share/man/man1/python.1.gz

将/usr/bin/python 的软连接修改为python2.4.3

[root@localhost Python-2.7.4]# mv /usr/bin/python /usr/bin/python2.4.3

[root@localhost Python-2.7.4]# python

-bash: /usr/bin/python: 没有那个文件或目录

python命令找不到,这时只需要将版本python2.7.4命令加入环境变量即可!

方式1:

修改/etc/profile加入如下两行:

PATH=$PATH:/usr/local/python2.7.4/bin

export PATH

然后

[root@localhost Python-2.7.4]# source /etc/profile

[root@localhost Python-2.7.4]# python -V

Python 2.7.4

当然也可以创建2.7.4版本的python的软连接:/usr/bin/python

[root@localhost ~]# ln -s /usr/local/python2.7.4/bin/python /usr/bin/python

亦可

ok,python升级完成

到现在为止,还有最后一件事需要做,那就是yum与python的兼容问题:

[root@localhost pipe]# vi /usr/bin/yum

#!/usr/bin/python

第一行修改为

#!/usr/bin/python2.4.3(即原始的python变更后的名字)

首先下载源tar包

  可利用linux自带下载工具wget下载,如下所示:

1
#
wget http://www.python.org/
ftp
/python/3.3.0/Python-3.3.0.tgz
  或自己去网上找,这里提供一个最新版的下载链接:http://xiazai.zol.com.cn/detail/33/320958.shtml

  这里我用的是第二种方法,下载的是Python-3.1.2.tar.bz2版本,下载完成后到下载目录下,解压

1
bunzip2
Python-3.1.2.tar.bz2
2
tar
-xvf
Python-3.1.2.tar
(若是第一种方法,则直接解压缩tar
-xzvf Python-3.3.0.tgz)[/code]
  进入解压缩后的文件夹
1
cd
Python-3.1.2
  在编译前先在/usr/local建一个文件夹python3(作为python的安装路径,以免覆盖老的版本)

1
mkdir
/usr/
local
/python3
  开始编译安装

1
./configure
--prefix=/usr/
local
/python3
2
make
3
make
install
  此时没有覆盖老版本,再将原来/usr/bin/python链接改为别的名字

1
mv
/usr/bin/python
/usr/bin/python_old
  再建立新版本python的链接

1
ln
-s
/usr/
local
/python3/bin/python3
/usr/bin/python
  这个时候输入

1
python
  就会显示出python的新版本信息

1
Python
3.1.2 (r312:79147,Oct 21 2012,01:03:21))
2
[GCC
3.2.2 20030222 (Red Hat Linux 3.2.2-5)] on linux2
3
Type
"help"
,
"copyright"
,
"credits"
or
"license"
for
more
information.
4
>>>
  PS:如果不建立新安装路径python3,而是直接默认安装,则安装后的新python应该会覆盖linux下自带的老版本,也有可能不覆盖,具体看安装过程了,这个大家可以自己试验下,当然如果还想保留原来的版本,那么这种方法最好不过了。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: