上周利用一周的时间学习了《A Byte of Python》,基本掌握了 Python 语言,但我作为一名系统工程师,基本告别了令人讨厌的编码工作,所以学习 Python 的主要原因除了爱好,就是想用它进行系统管理,所以我又开始读《Python for Unix and Linux System Administration》这本书,我开始尝试用 Python 来进行系统配置。工欲善其事,必先利其器!使用 Python 进行系统管理,当然首推 IPython,IPython 是一种“高级交互式Python”, 除了包含内置的交互解释器的功能(当然这个用起来感觉还是不一样地)以外还提供了一组灰常灰常有用的工具。Fernando Pérez 是 iPython 的创建者,他通过阅读《IPP and LazyPython》产生了灵感,现在他是 IPython 对象的核心开发人。在 Fernando 看来,IPython 是一种能够解决问题的高度可配置的工具。

下面我来介绍一下在 RHEL 5.5 下如何安装 Python 和 IPython。我的 RHEL 5.5 64bit 预装的是 Python 2.4.3,版本比较老,而 iPython 0.11 要求 Python 的版本至少是2.6。好在可以在一个系统上安装多个版本的 Python,前提是不要安装在同一个目录中,具体的安装配置过程如下:

  1. 使用 yum 安装 Python 的依赖包。
    yum -y install gcc gdbm-devel readline-devel ncurses-devel zlib-devel bzip2-develsqlite-devel db4-devel openssl-devel tk-devel bluez-libs-devel make
  2. 编译安装 Python 程序包。
    [root@pubservicedb ~]# tar -xvf Python-2.7.2.tar.bz2
    [root@pubservicedb ~]# cd Python-2.7.2
    [root@pubservicedb Python-2.7.2]# ./configure --prefix=/usr/local/python2.7 --with-threads --enable-shared
    [root@pubservicedb Python-2.7.2]# make
    [root@pubservicedb Python-2.7.2]# make install
  3. 创建软连接。
    [root@pubservicedb Python-2.7.2]# ln -sf /usr/local/python2.7/bin/python2.7 /usr/bin/python2.7
  4. 如果运行上一步创建的软连接报函数库没有加载的错误,请配置 Python 函数库:
    [root@pubservicedb Python-2.7.2]# python2.7
    python2.7: error while loading shared libraries: libpython2.7.so.1.0: cannot open shared object file: No such file or directory
    [root@pubservicedb Python-2.7.2]# touch /etc/ld.so.conf.d/python2.7.conf
    [root@pubservicedb Python-2.7.2]# echo "/usr/local/python2.7/lib/" >> /etc/ld.so.conf.d/python2.7.conf
    [root@pubservicedb Python-2.7.2]# cat /etc/ld.so.conf.d/python2.7.conf
    [root@pubservicedb Python-2.7.2]# ldconfig
    [root@pubservicedb Python-2.7.2]# python2.7
    Python 2.7.2 (default, Nov 1 2011, 14:00:46)
    [GCC 4.1.2 20080704 (Red Hat 4.1.2-48)] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>>
    [root@pubservicedb Python-2.7.2]#
  5. 安装 IPython 程序包。
    [root@pubservicedb ~]# tar -xvf ipython-0.11
    [root@pubservicedb ~]# cd ipython-0.11
    [root@pubservicedb ipython-0.11]# python2.7 setup.py install
    [root@pubservicedb python2.7]# ln -sf /usr/local/python2.7/bin/ipython /usr/bin/ipython
    [root@pubservicedb python2.7]# ipython
    Python 2.7.2 (default, Nov 1 2011, 14:00:46)
    Type "copyright", "credits" or "license" for more information.

    IPython 0.11 -- An enhanced Interactive Python.
    ? -> Introduction and overview of IPython's features.
    %quickref -> Quick reference.
    help -> Python's own help system.
    object? -> Details about 'object', use 'object??' for extra details.
    In [1]: exit()
    [root@pubservicedb ipython]#

  6. 大功告成!

本文使用的是源代码安装的方式来安装的 IPython,其实如果系统上安装了 setuptools,那么你可以使用 easy_install 来安装,或者直接下载 IPython 的 egg 包再配置好相关环境后直接使用。如果你对 setuptools 和 egg 包的概念不是很理解,请参考这篇文章

相关日志:

Tagged with:
 

发表评论

电子邮件地址不会被公开。 必填项已用 * 标注

*


*

您可以使用这些 HTML 标签和属性: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

使用腾讯微博登陆

Looking for something?

Use the form below to search the site:


Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

Visit our friends!

A few highly recommended friends...