系统:Centos6.4 X86_64 默认版本为2.6.6
准备软件包:系统默认版本2.6.6 这里安装2.7.6 默认版本不要动。
ipython-1.2.1.tar.gz Python-2.7.6.tar.xz
ipython 是一个 python 的交互式 shell,比默认的python shell 好用得多,支持变量自动补全,自动缩进,支持 bash shell 命令,内置了许多很有用的功能和函数。在ubuntu 下只要 sudo apt-get install ipython 就装好了,通过 ipython 启动。
安装过程:
[root@node1 ~]# tar xf Python-2.7.6.tar.xz
[root@node1 ~]# cd Python-2.7.6
[root@node1 Python-2.7.6]# ls
config.guess configure Demo Grammar install-sh LICENSE Makefile.pre.in Modules Parser PCbuild Python RISCOS Tools
config.sub configure.ac Doc Include Lib Mac Misc Objects PC pyconfig.h.in README setup.py
[root@node1 Python-2.7.6]# yum install readline-devel -y #编译出的python可以使用删除键等。
[root@node1 Python-2.7.6]# ./configure --prefix=/usr/local/python27
[root@node1 Python-2.7.6]# make && make install
[root@node1 Python-2.7.6]# cd /usr/local/python27/bin
[root@node1 bin]# ls
2to3 idle pydoc python python2 python2.7 python2.7-config python2-config python-config smtpd.py
[root@node1 bin]# pwd
/usr/local/python27/bin
[root@node1 bin]# ./python2.7
Python 2.7.6 (default, Feb 26 2016, 11:02:52)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-16)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> print "hello world"
hello world
安装ipython
[root@node1 python]# tar xf ipython-1.2.1.tar.gz
[root@node1 python]# cd ipython-1.2.1
[root@node1 ipython-1.2.1]# /usr/local/python27/bin/python2.7 setup.py build
[root@node1 ipython-1.2.1]# /usr/local/python27/bin/python2.7 setup.py install
[root@node1 ipython-1.2.1]# ls /usr/local/python27/bin/
2to3 ipcluster ipengine iptest irunner pydoc python2 python2.7-config python-config
idle ipcontroller iplogger ipython pycolor python python2.7 python2-config smtpd.py
做命令连接方便使用
[root@node1 ipython-1.2.1]# ln -sv /usr/local/python27/bin/python2.7 /usr/local/bin/python27
"/usr/local/bin/python27" -> "/usr/local/python27/bin/python2.7"
[root@node1 ipython-1.2.1]# ln -sv /usr/local/python27/bin/ipython /usr/local/bin/
"/usr/local/bin/ipython" -> "/usr/local/python27/bin/ipython"
使用ipython
[root@node1 ~]# ipython
WARNING: IPython History requires SQLite, your history will not be saved
Python 2.7.6 (default, Feb 26 2016, 11:02:52)
Type "copyright", "credits" or "license" for more information.
IPython 1.2.1 -- 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]: print "hello world"
hello world
In [2]: import platform
In [3]: print
In [3]: print platform
<module 'platform' from '/usr/local/python27/lib/python2.7/platform.pyc'>
完成。