设为首页 收藏本站
查看: 1246|回复: 0

[经验分享] Redhat Linux下的python版本号升级

[复制链接]

尚未签到

发表于 2015-12-2 12:05:37 | 显示全部楼层 |阅读模式
运行#Python与#python -V,看到版本是2.4.3,非常老了,并且之前写的都是跑在python3.X上面的,3.X和2.X有非常多不同,
有兴趣的朋友能够參考下这篇文章:
http://www.iyunv.net/article/34011.htm

更新python千万不要把老版本号的删除!新老版本号是能够共存的,非常多主要的命令、
软件包都要依赖预装的老版本号python的,比方yum。

一、升级到2.7.3
1. 升级安装
首先下载源tar包
可利用linux自带下载工具wget下载,例如以下所看到的:
# wget http://www.python.org/ftp/python/2.7.3/Python-2.7.3.tar.gz

下载完毕后到下载文件夹下,解压
# tar -zxvf Python-2.7.3.tar.gz

进入解压缩后的目录
cd Python-2.7.3

在编译前先在/usr/local建一个目录python2.7.3(作为python的安装路径,以免覆盖老的版本号)
# mkdir /usr/local/python2.7.3

在解压缩后的文件夹下编译安装
# ./configure --prefix=/usr/local/python2.7.3
# make
# make install

此时没有覆盖老版本号,再将原来/usr/bin/python链接改为别的名字
# mv /usr/bin/python /usr/bin/python_old

再建立新版本号python的链接
# ln -s /usr/local/python2.7.3/bin/python2.7 /usr/bin/python

这个时候输入
# python

就会显示出python的新版本号信息
view sourceprint?
Python 2.7.3 (default, Sep 29 2013, 11:05:02)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-54)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>

2.执行程序时出现错误:
File "~/PythonInstall/lib/python2.7/multiprocessing/process.py", line 129, in start
    from .forking import Popen
  File "~/PythonInstall/lib/python2.7/multiprocessing/forking.py", line 58, in <module>
    from pickle import Pickler
  File "~/PythonInstall/lib/python2.7/pickle.py", line 1266, in <module>
    import binascii as _binascii
ImportError: No module named binascii
是由于升级python版本号不正常导致的。

回到源文件文件夹:
# cd .../Python-2.7.3
[Python-2.7.3]# make -s
building dbm using gdbm
/opt/PJT_python/python-2.7.3/Python-2.7.3/Modules/_sqlite/connection.c: In function '_pysqlite_set_result':
/opt/PJT_python/python-2.7.3/Python-2.7.3/Modules/_sqlite/connection.c:552: error: 'sqlite3_int64' undeclared

(first use in this function)
/opt/PJT_python/python-2.7.3/Python-2.7.3/Modules/_sqlite/connection.c:552: error: (Each undeclared identifier is

reported only once
/opt/PJT_python/python-2.7.3/Python-2.7.3/Modules/_sqlite/connection.c:552: error: for each function it appears in.)
/opt/PJT_python/python-2.7.3/Python-2.7.3/Modules/_sqlite/connection.c:552: error: expected ')' before

'PyInt_AsLong'
/opt/PJT_python/python-2.7.3/Python-2.7.3/Modules/_sqlite/connection.c: In function '_pysqlite_build_py_params':
/opt/PJT_python/python-2.7.3/Python-2.7.3/Modules/_sqlite/connection.c:583: error: 'sqlite3_int64' undeclared
(first use in this function)
/opt/PJT_python/python-2.7.3/Python-2.7.3/Modules/_sqlite/connection.c:583: error: expected ';' before 'val_int'
/opt/PJT_python/python-2.7.3/Python-2.7.3/Modules/_sqlite/connection.c:596: error: 'val_int' undeclared (first use  inthis function)
/usr/bin/ld: /usr/local/lib/libz.a(adler32.o): relocation R_X86_64_32 against `a local symbol' can not be used when

making a shared object; recompile with -fPIC
/usr/local/lib/libz.a: could not read symbols: Bad value
collect2: ld returned 1 exit status
/usr/bin/ld: /usr/local/lib/libz.a(crc32.o): relocation R_X86_64_32 against `a local symbol' can not be used when

making a shared object; recompile with -fPIC
/usr/local/lib/libz.a: could not read symbols: Bad value
collect2: ld returned 1 exit status

Python build finished, but the necessary bits to build these modules were not found:
_tkinter           bsddb185           dl              
imageop            sunaudiodev                        
To find the necessary bits, look in setup.py in detect_modules() for the module's name.

Failed to build these modules:
_sqlite3           binascii           zlib

升级安装zlib
# wget http://sourceforge.net/projects/libpng/files/zlib/1.2.8/zlib-1.2.8.tar.gz
# tar -zxvf zlib-1.2.8.tar.gz
# cd zlib-1.2.8
# ./configure
# make install

# cd ../Python-2.7.3
# make -s
building dbm using gdbm
/opt/PJT_python/python-2.7.3/Python-2.7.3/Modules/_sqlite/connection.c: In function '_pysqlite_set_result':
/opt/PJT_python/python-2.7.3/Python-2.7.3/Modules/_sqlite/connection.c:552: error: 'sqlite3_int64' undeclared

(first use in this function)
/opt/PJT_python/python-2.7.3/Python-2.7.3/Modules/_sqlite/connection.c:552: error: (Each undeclared identifier is reportedonly once
/opt/PJT_python/python-2.7.3/Python-2.7.3/Modules/_sqlite/connection.c:552: error: for each function it appears in.)
/opt/PJT_python/python-2.7.3/Python-2.7.3/Modules/_sqlite/connection.c:552: error: expected ')' before

'PyInt_AsLong'
/opt/PJT_python/python-2.7.3/Python-2.7.3/Modules/_sqlite/connection.c: In function '_pysqlite_build_py_params':
/opt/PJT_python/python-2.7.3/Python-2.7.3/Modules/_sqlite/connection.c:583: error: 'sqlite3_int64' undeclared

(first use in this function)
/opt/PJT_python/python-2.7.3/Python-2.7.3/Modules/_sqlite/connection.c:583: error: expected ';' before 'val_int'
/opt/PJT_python/python-2.7.3/Python-2.7.3/Modules/_sqlite/connection.c:596: error: 'val_int' undeclared (first use inthis function)

Python build finished, but the necessary bits to build these modules were not found:
_tkinter           bsddb185           dl              
imageop            sunaudiodev                        
To find the necessary bits, look in setup.py in detect_modules() for the module's name.

Failed to build these modules:
_sqlite3

升级安装sqlite3
# cd ..
# wget http://www.sqlite.org/2014/sqlite-autoconf-3080500.tar.gz
# tar -zxvf sqlite-autoconf-3080500.tar.gz
# cd sqlite-autoconf-3080500
# ./configure
# make
# make install

# cd ..
# cd python-2.7.3
# make -s
building dbm using gdbm

Python build finished, but the necessary bits to build these modules were not found:
_tkinter           bsddb185           dl              
imageop            sunaudiodev                        
To find the necessary bits, look in setup.py in detect_modules() for the module's name.

# make clean
# make all
# make install

到此,程序就能正常执行了;

二、升级到3.3.0
更新python:
第1步:更新gcc,
由于gcc版本号太老会导致新版本号python包编译不成功 代码例如以下:
  #yum -y install gcc

系统会自己主动下载并安装或更新,等它自己结束

第2步:下载Python-3.3.0软件包
代码例如以下:
# wget --no-check-certificate http://python.org/ftp/python/3.3.0/Python-3.3.0.tar.bz2

注意:依照上述命令下载的软件包会存放在你当前的工作文件夹下,
wget命令是一个从网络上自己主动下载文件的自由工具,详细使用方法,
请參考这篇文章:http://www.iyunv.net/os/RedHat/73089.html

说明:命令中的数字就是版本号号,你也能够把3.3.0换成你须要的版本号.

第3步:解压已下载的二进制包并编译安装
代码例如以下:
#tar -jxvf Python-3.3.0.tar.bz2
#cd Python-3.3.0
#./configure
#make all
#make install
#make clean
#make distclean
# /usr/local/bin/python3 –V
编译安装完成以后,能够输入上面一行命令,查看版本号

第4步:建立软连接指向到当前系统默认python命令的bin文件夹,让系统使用新版本号python
#mv /usr/bin/python /usr/bin/python2.4 //当前python的版本号为2.4所以是python2.4
#ln -s /usr/local/bin/python3.3 /usr/bin/python
输入
#python -V,
就可以查看当前默认python版本号
默认的python成功指向3.3.0以后,yum不能正常使用,须要改动yum的配置文件

第5步:改动yum配置文件
#vi /usr/bin/yum
把文件头部的
#!/usr/bin/python  改成  #!/usr/bin/python2.4 //改为之前的老版本
保存退出,yum就可以正常使用。

如若有其它命令、软件不能正常使用,仿照yum配置文件的改动方法,改动其配置文件就可以。
至此,更新完成。

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-146305-1-1.html 上篇帖子: centos 6.5使用virtualenv指定python 2.7.x 下篇帖子: leetcode 【 Intersection of Two Linked Lists 】python 实现
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表