Redhat Linux下的python版本升级

执行#Python与#python -V,看到版本号是2.4.3,很老了,而且之前写的都是跑在python3.X上面的,3.X和2.X有很多不同,

有兴趣的朋友可以参考下这篇文章:

http://www.jb51.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  in
this 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 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 in
this 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.jb51.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配置文件的修改方法,修改其配置文件即可。

至此,更新完毕。

Redhat Linux下的python版本升级

时间: 2024-08-11 19:57:10

Redhat Linux下的python版本升级的相关文章

Redhat Linux下的python版本号升级

运行#Python与#python -V,看到版本是2.4.3,非常老了,并且之前写的都是跑在python3.X上面的,3.X和2.X有非常多不同, 有兴趣的朋友能够參考下这篇文章: http://www.jb51.net/article/34011.htm 更新python千万不要把老版本号的删除!新老版本号是能够共存的,非常多主要的命令. 软件包都要依赖预装的老版本号python的,比方yum. 一.升级到2.7.3 1. 升级安装 首先下载源tar包 可利用linux自带下载工具wget下

Linux下升级Python到3.5.2版本

原文出处:https://www.cnblogs.com/tssc/p/7762998.html 本文主要介绍在Linux(CentOS)下将Python的版本升级为3.5.2的方法 众所周知,在2020年python官方将不再支持2.7版本的python,所以使用3.x版本的python是必要的,但是linux中默认安装的python一般是2.6和2.7版本的,要是使用linux下的python就很有必要升级一下 进入正题 1.检查确认系统的相关信息 [[email protected] ~]

linux下的python基本介绍

[python]linux下的python安装及初步学习 linux下python的安装 尽管我的unbuntu 10.11版本已经默认更新了python的安装,但这里还是重新介绍一下如何在linux下安装   python.在网上也有一些安装教程. 摘来如下 1.下载源代码 http://www.python.org/ftp/python/2.5.2/Python-2.5.2.tar.bz2 2. 安装 $ tar –jxvf Python-2.5.2.tar.bz2 $ cd Python-

【转】Linux 下安装python软件包(pip、nose、virtualenv、distribute )

1.关于pip pip是python的软件安装工具,下面是pip的使用方法: (1)安装包:pip install SomePackage (2)查看安装包时安装了哪些文件:pip show --files SomePackage (3)查看哪些包有更新:pip show --files SomePackage (4)更新一个软件:pip install --upgrade SomePackage (5)卸载软件:pip uninstall SomePackage 所以,有了pip我们就可以自动

Linux 下安装python软件包(pip、nose、virtualenv、distribute )

新手刚开始学习Python,目前学习<笨方法学python>ing- 在学习习题46时需要安装几个软件包:pip.nose.virtualenv.distribute !在此记录Linux下安装python软件包的安装方法: 1.首先我们刚刚pip是什么? 在pip的python官网上我们可以看到,pip 是“A tool for installing and managing Python packages.”,也就是说pip是python的软件安装工具,下面是pip的使用方法: 安装包:

linux下更新Python版本并修改默认版本

linux下更新Python版本并修改默认版本,有需要的朋友可以参考下. 很多情况下拿到的服务器python版本很低,需要自己动手更改默认python版本 1.从官网下载python安装包(这个版本可以是任意版本3.3 2.7 2.6等等) wget http://python.org/ftp/python/2.7/Python-2.7.tar.bz2 2.解压并安装 tar -jxvf Python-2.7.tar.bz2 cd Python-3.3.0 ./configure make al

Linux下使用Python操作MySQL数据库

安装mysql-python 1.下载mysql-python 打开终端: cd /usr/local sudo wget http://nchc.dl.sourceforge.net/sourceforge/mysql-python/MySQL-python-1.2.2.tar.gz 官网地址:http://sourceforge.net/projects/mysql-python/ 2.解压 sudo tar -zxvf MySQL-python-1.2.2.tar.gz cd MySQL-

linux 下写python脚本实现自动补全( 我51论坛也有)

以前都是在windows下开发,但是对于玩linux的人来说,能够在linux下实现python脚本的自动补全的话,那是相当不错的,而我一般是使用的vim作为编辑器,且linux一般选择最小化安装,没有图形界面,参考了下网上的很多方法也没有适合自己,最后自己去看代码的帮助来实现了这个功能,废话不说,现在开始代码下载地址:http://vim.sourceforge.net/scripts/download_script.php?src_id=21842 文件名:pydiction-1.2.3.z

RedHat Linux下MQ安装步骤及MQ常用命令

1.检查操作系统及内存情况:lsb_release -a; 2   检查java 环境:java -version 3   新建用户空间.用户和组: //创建用户目录 mkdir /home/mqm //创建用户组 groupadd mqm //创建用户 useradd -g mqm -d /home/mqm -m -s /bin/bash mqm 4 创建MQ安装文件夹: //更改目录权限 chown -R mqm:mqm /home/mqm //创建MQ安装位置和工作空间 mkdir /op