posts - 38, comments - 13, trackbacks - 0, articles - 0
  IT博客 :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理

Red Hat Linux下安装Pyyhon

Posted on 2009-12-28 18:19 大源 阅读(975) 评论(0)  编辑 收藏 引用 所属分类: Python

1、下载源代码
http://www.python.org/ftp/python/3.1/Python-3.1.tar.bz2

2、安装

[root@localhost Python]# tar -jxvf Python-3.1.tar.bz2
[root@localhost Python]# cd Python-3.1
[root@localhost Python-3.1]# ./configure           默认安装在/usr/bin/Python目录下
[root@localhost Python-3.1]# make
[root@localhost Python-3.1]# make install
[root@localhost Python-3.1]# make clean
[root@localhost Python-3.1]# make distclean

一些配置信息及安装目录
PYTHONPATH=/usr/local/lib/python3.1 

./python.exe -E ./setup.py install \
                --prefix=/usr/local \
                --install-scripts=/usr/local/bin \
                --install-platlib=/usr/local/lib/python3.1/lib-dynload \
                --root=/

默认安装在:/usr/local
可执行文件:/usr/local/bin
库文件:/usr/local/lib/python3.1
头文件:/usr/local/include/python3.1


3、测试

在命令行下输入python,出现python解析器就表示已经安装成功

[root@localhost Python-3.1]# python
Python 2.4.3 (#1, Dec 11 2006, 11:38:52)
[GCC 4.1.1 20061130 (Red Hat 4.1.1-43)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>

但是在Red Hat Linux 5下,系统已经默认安装了python2.4,命令行输入python,发现显示的结果仍然是python2.4.3,
可是我们这里的版本号是python3.1

解决办法,删除python2.4,如下所示:
[root@localhost ~]# rpm -qa |grep python      //查找python2.4相关的rpm包

notify-python-0.1.0-3.fc6
gnome-python2-2.16.0-1.fc6
gnome-python2-gtksourceview-2.16.0-1.fc6
audit-libs-python-1.3.1-1.el5
gamin-python-0.1.7-8.el5
mod_python-3.2.8-3.1
gnome-python2-gconf-2.16.0-1.fc6
dbus-python-0.70-7.el5
python-numeric-23.7-2.2.2
python-devel-2.4.3-19.el5
gnome-python2-canvas-2.16.0-1.fc6
gnome-python2-applet-2.16.0-1.fc6
gnome-python2-gnomevfs-2.16.0-1.fc6
python-2.4.3-19.el5
libxml2-python-2.6.26-2.1.2
rpm-python-4.4.2-37.el5
python-urlgrabber-3.1.0-2
python-sqlite-1.1.7-1.2.1
python-ldap-2.2.0-2.1
gnome-python2-gtkhtml2-2.14.2-4.fc6
gnome-python2-gnomeprint-2.16.0-1.fc6
gnome-python2-bonobo-2.16.0-1.fc6
python-elementtree-1.2.6-5
gnome-python2-desktop-2.16.0-1.fc6
gnome-python2-libegg-2.14.2-4.fc6
libselinux-python-1.33.4-2.el5
gnome-python2-extras-2.14.2-4.fc6

[root@localhost ~]# rpm -e python-devel-2.4.3-19.el5 --nodeps     //删除python2.4相关的rpm包 
[root@localhost ~]# which python3.1         //查找python3.1安装目录
/usr/local/bin/python3.1

 
//直接在命令行中输入python3.1,来调入python3.1的解析器,如果以后安装了pythonx.x,则不需要删除老版本的python,而是

直接在shell中输入pythonx.x就可以调用当前版本的解析器了,很方便,在 #! 行中 (每个脚本的第一行) 使用它来确保脚本运行在最新版的 Python 下,并且确保敲入的是 python3.1 进入交互shell。

[root@localhost ~]# python3.1         
Python 3.1 (r31:73572, Dec 28 2009, 18:30:37)
[GCC 4.1.1 20070105 (Red Hat 4.1.1-52)] on linux2
Type "help", "copyright", "credits" or "license" for

more information.
>>>

按CTRL+D来退出Python。
[root@localhost ~]#

修改Linux系统中的默认Python版本,方法如下:
[root@localhost bin]# ln -s /usr/local/bin/python3.1 ./python        //usr/local/bin/python3.1是指最新版本的安装目录
[root@localhost bin]# python
Python 3.1 (r31:73572, Dec 28 2009, 18:30:37)
[GCC 4.1.1 20070105 (Red Hat 4.1.1-52)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>

只有注册用户登录后才能发表评论。