一、编译前准备
1、准备源码包
1
2
|
[root@node3 ~]
# wget https://www.python.org/ftp/python/2.7.12/Python-2.7.12.tar.xz
[root@node3 ~]
# wget http://archive.ipython.org/release/1.2.1/ipython-1.2.1.tar.gz
|
2、准备编译环境
2.1python编译所需的包
1
2
|
[root@node3 ~]
# yum install readline-devel
[root@node3 ~]
# yum install zlib*
|
2.2安装开发包组
1
|
[root@node3 ~]
# yum groupinstall "Development tools"
|
二、编译安装
1、python编译安装
1
2
3
4
|
[root@node3 ~]
# tar xf Python-2.7.12.tar.xz
[root@node3 ~]
# cd Python-2.7.12
[root@node3 Python-2.7.12]
# ./configure --prefix=/usr/local/python27
[root@node3 Python-2.7.12]
# make && make install
|
2、ipython模块编译安装
1
2
3
4
|
[root@node3 ~]
# tar xf ipython-1.2.1.tar.gz
[root@node3 ~]
# cd ipython-1.2.1
[root@node3 ipython-1.2.1]
# /usr/local/python27/bin/python2.7 setup.py install
[root@node3 ipython-1.2.1]
# /usr/local/python27/bin/python2.7 setup.py build
|
3、添加软连接
1
2
3
4
|
[root@node3 ~]
# ln -sv /usr/local/python27/bin/python2.7 /usr/bin/python27
`
/usr/bin/python27
' -> `/usr/local/python27/bin/python2.7'
[root@node3 ~]
# ln -sv /usr/local/python27/bin/ipython /usr/bin/
`
/usr/bin/ipython
' -> `/usr/local/python27/bin/ipython'
|
三、setuptools的编译安装
1、准备源码
1
|
[root@node3 ~]
# wget https://pypi.python.org/packages/e8/68/f968ebc015c7e0021e76b60b8cfd29f9ffbae4b3b58d96ad20045a99562e/setuptools-32.3.1.zip#md5=efa64884dd41d2b0456e19745bb29fdc
|
2、解压缩
1
|
[root@node3 ~]
# unzip setuptools-32.3.1.zip
|
3、编译安装
1
2
|
[root@node3 setuptools-32.3.1]
# /usr/local/python27/bin/python2.7 setup.py build
[root@node3 setuptools-32.3.1]
# /usr/local/python27/bin/python2.7 setup.py install
|
遇见报错:
1
2
3
4
5
|
File
"/root/setuptools-1.1.1/setuptools/command/bdist_egg.py"
, line 545,
in
make_zipfile
z = zipfile.ZipFile(zip_filename, mode, compression=compression)
File
"/usr/local/python27/lib/python2.7/zipfile.py"
, line 736,
in
__init__
"Compression requires the (missing) zlib module"
RuntimeError: Compression requires the (missing) zlib module
|
此处的报错为没安装zlib压缩模块,这个模块应在python编译安装之前安装。此时,只有重新编译python,方能解决。
四、安装MySQLdb模块
1、下载 https://pypi.python.org/pypi/MySQL-python/1.2.5
1
|
[root@node3 ~]
# wget https://pypi.python.org/packages/a5/e9/51b544da85a36a68debe7a7091f068d802fc515a3a202652828c73453cad/MySQL-python-1.2.5.zip#md5=654f75b302db6ed8dc5a898c625e030c
|
2、编译安装
1
2
3
|
[root@node3 ~]
# unzip MySQL-python-1.2.5.zip
[root@node3 MySQL-python-1.2.5]
# /usr/local/python27/bin/python2.7 setup.py build
[root@node3 MySQL-python-1.2.5]
# /usr/local/python27/bin/python2.7 setup.py install
|
遇见报错:
1
2
3
|
File
"/root/MySQL-python-1.2.5/setup_posix.py"
, line 25,
in
mysql_config
raise EnvironmentError(
"%s not found"
% (mysql_config.path,))
EnvironmentError: mysql_config not found
|
这个报错原因是没有安装mysql,安装mysql即可。
本文转自 元婴期 51CTO博客,原文链接:http://blog.51cto.com/jiayimeng/1881888