从官网下载python源码包解压源码包cd python-x.x.x进入解压后的源码包
配置#./configure --prefix=/usr/local/python2.7 --enable-shared
configure 是一个可执行脚本,它有很多选项,使用命令 #./configure –help 输出详细的选项列表 ./configure --prefix=/usr/local/python2.7表示安装到/usr/local目录
编译 #make
安装 make install
将python放入PATH变量中 ln -s /usr/local/python2.7/bin/python2.7 /usr/bin/python
运行python可能会报 python: error while loading shared libraries: libpython2.7.so.1.0: cannot open shared object file: No such file or directory 解决办法:
# vi /etc/ld.so.conf
添加新行:/usr/local/python2
.7/lib
保存后,运行
# /sbin/ldconfig
# /sbin/ldconfig –v
最后运行python命令