1.下载源代码
http://www.python.org/ftp/python/2.7.3/Python-2.7.3.tar.bz2
2.安装
安装目录一般为/usr/local/,进入该目录
①解压安装文件
- $ tar –jxvf Python-2.7.3.tar.bz2
②进入解压后的目录
- $ cd Python-2.7.3
③执行安装步骤
- $ ./configure
- $ make
- $ make install
3. 测试
在命令行下输入python,出现python解释器即表示已经正确安装。
某些系统默认已经装了python但版本是2.4.x;由于版本太低,高版本的命令并不使用,本次安装后在shell中输入
#python
会发现显示结果:
# 2.4.3
- Python 2.4.3 (#1, May 5 2011, 16:39:10)
- [GCC 4.1.2 20080704 (Red Hat 4.1.2-50)] on linux2
- Type "help", "copyright", "credits" or "license" for more information.
版本还是2.4.x的,由于python不像java可以设置JAVA_HOME环境变量,因此需要其他方式
解决办法:
- #cd /usr/bin
- #ll |grep python //查看该目录下python
- #rm -rf python
- #ln -s /usr/local/Python-2.7.3/python ./python //建立对应的软链接
- #python
- # python
- Python 2.7.3 (default, Aug 20 2012, 15:37:12)
- [GCC 4.1.2 20080704 (Red Hat 4.1.2-50)] on linux2
- Type "help", "copyright", "credits" or "license" for more information.
安装成功。