CentOS6.x系统中一直沿用的都是Python2.6.x(目前最新版本是python-2.6.6),有时不能满足某些应用生产环境和开发环境的需要,直接从yum官方仓库和epel中安装Python2.7(目前最新版本是python-2.7.12)似乎也是没有什么可能,除非使用更三方的软件源。CentOS6.x系统中有很多系统组件是使用Python2.6的,比如刚才提到的yum,但yum不一定是唯一依赖Python2.6的程序,尽管一般的生产环境中不会使用到特别混杂的运行环境,但在使用的过程中需要留意某些工具&程序是否能在Python2.7下正常运行。
安装Python2.7.x实际上非常简单,唯一需要了解的是,编译安装Python2.7.x时必须将使用--enable-shared (enable building shared python library)选项用来安装python动态链接库(share object, /usr/lib64/libpython2.7.so.1.0),这一文件会被很多python模块(甚至python本身)所用到,当没有使用这一选项时可以加上这个选项重新编译Python,步骤见下文。
下载地址:https://www.python.org/downloads/
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
wget -c https:
//www
.python.org
/ftp/python/2
.7.12
/Python-2
.7.12.tgz
wget -c https:
//www
.python.org
/ftp/python/2
.7.12
/Python-2
.7.12.tgz.asc
wget https:
//www
.python.org
/static/files/pubkeys
.txt
gpg --
import
pubkeys.txt
gpg --recv-keys 6A45C816 36580288 7D9DC8D2 18ADD4FF A4135B38 A74B06BF EA5BBD71 ED9D77D5 E6DF025C AA65421D 6F5E1540 F73C700D 487034E5
gpg --verify Python-2.7.12.tgz.asc
# Good signature
tar
zxf Python-2.7.12.tgz
cd
Python-2.7.12/
yum
install
-y gcc gcc-c++ openssl-devel
.
/configure
--
enable
-shared
make
&&
make
install
echo
'/usr/local/lib'
>
/etc/ld
.so.conf.d
/libpython2
.7.conf
ldconfig
python --version
sed
-i
'1 s/python/python2.6/g'
/usr/bin/yum
wget https:
//bootstrap
.pypa.io
/ez_setup
.py
python ez_setup.py
# setuptools
easy_install --version
wget https:
//bootstrap
.pypa.io
/get-pip
.py
python get-pip.py
# pip
pip --version
|
tag: CentOS Python2.7,centos安装python2.7,编译安装python2.7
--end--
本文转自 urey_pp 51CTO博客,原文链接:http://blog.51cto.com/dgd2010/1876660,如需转载请自行联系原作者