http://blog.csdn.net/my2010sam/article/details/12156821
sudo yum install openssl-devel
yum install zlib
yum install zlib-devel
首先下载源tar包
可利用linux自带下载工具wget下载,如下所示:
下载完成后到下载目录下,解压
1 | tar -zxvf Python-2.7.3.tgz |
进入解压缩后的文件夹
在编译前先在/usr/local建一个文件夹python27(作为python的安装路径,以免覆盖老的版本)
1 | mkdir /usr/ local /python27 |
在解压缩后的目录下编译安装
1 | ./configure --prefix=/usr/ local /python27 |
此时没有覆盖老版本,再将原来/usr/bin/python链接改为别的名字
1 | mv /usr/bin/python /usr/bin/python_old |
再建立新版本python的链接
1 | ln -s /usr/ local /python27/bin/python2.7 /usr/bin/python |
这个时候输入
就会显示出python的新版本信息
1 | Python 2.7.3 (default, Sep 29 2013, 11:05:02) |
2 | [GCC 4.1.2 20080704 (Red Hat 4.1.2-54)] on linux2 |
3 | Type "help" , "copyright" , "credits" or "license" for more information. |
查找yum和 yum-updatest文件,并编辑此py文件
- [root@develop local]# which yum
- /usr/bin/yum
- [root@develop local]# vi /usr/bin/yum
- [root@develop local]# vi /usr/bin/yum-updatest
将
#!/usr/bin/python
改为:
#!/usr/bin/python2.6
Traceback (most recent call last):
File "setup.py", line 94, in <module>
scripts = scripts,
File "/usr/local/lib/python2.7/distutils/core.py", line 152, in setup
dist.run_commands()
File "/usr/local/lib/python2.7/distutils/dist.py", line 953, in run_commands
self.run_command(cmd)
File "/usr/local/lib/python2.7/distutils/dist.py", line 972, in run_command
cmd_obj.run()
File "/opt/oracle/sor/install/setuptools-0.6c11/setuptools/command/install.py", line 76, in run
self.do_egg_install()
File "/opt/oracle/sor/install/setuptools-0.6c11/setuptools/command/install.py", line 96, in do_egg_install
self.run_command('bdist_egg')
File "/usr/local/lib/python2.7/distutils/cmd.py", line 326, in run_command
self.distribution.run_command(command)
File "/usr/local/lib/python2.7/distutils/dist.py", line 972, in run_command
cmd_obj.run()
File "/opt/oracle/sor/install/setuptools-0.6c11/setuptools/command/bdist_egg.py", line 236, in run
dry_run=self.dry_run, mode=self.gen_header())
File "/opt/oracle/sor/install/setuptools-0.6c11/setuptools/command/bdist_egg.py", line 527, in make_zipfile
z = zipfile.ZipFile(zip_filename, mode, compression=compression)
File "/usr/local/lib/python2.7/zipfile.py", line 681, in __init__
"Compression requires the (missing) zlib module"
RuntimeError: Compression requires the (missing) zlib module
出错原因:
提示的很清楚,缺少 zlib模块导致安装失败
处理方式:
# yum install zlib
# yum install zlib-devel
下载成功后,进入python2.7的目录,重新执行
#make
#make install
此时先前执行的 软连接仍旧生效
然后进入 setuptool目录,
[root@localhost setuptools-5.2]# pythonnew setup.py install 重新安装
基本这样就可以搞定