简介
CentOS系统安装Python2.7有两种方式:
- 源码安装
- YUM安装
网上大部分教程都是通过源码安装,首先安装比较麻烦,源码安装后还不包含pip,setuptools等工具,需要单独安装。安装过程还会碰到各种疑难杂症。
YUM安装,CentOS6版本默认没有python27的rpm包,需要通过其他第三方repo获取安装包。
源码安装
# wget https://www.python.org/ftp/python/2.7.12/Python-2.7.12.tgz
# tar xf Python-2.7.12.tgz
# cd Python-2.7.12
# ./configure --prefix=/usr/local/python27
# make
# make install
YUM安装
需要使用到RHEL/CentOS提供的SCL源(软件集)
配置 SCL 源
# yum install centos-release-SCL
# yum install scl-utils-build
# yum --disablerepo="*" --enablerepo="centos-sclo-rh" list
# yum install python27 -y
配置Python27以来的系统模块
# find / -name libpython2.7.so.1.0
/opt/rh/python27/root/usr/lib64/libpython2.7.so.1.0
# echo '/opt/rh/python27/root/usr/lib64/' > /etc/ld.so.conf.d/python27.conf
# /sbin/ldconfig
# /sbin/ldconfig –v
验证Python27
# /opt/rh/python27/root/usr/bin/python2.7
Python 2.7.8 (default, Oct 22 2016, 09:02:55)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-17)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>