查看python的版本
#python -V
Python 2.6.6
1.下载Python-2.7.3
#wget http://python.org/ftp/python/2.7.3/Python-2.7.3.tar.bz2
2.解压
#tar -jxvf Python-2.7.3.tar.bz2
3.更改工作目录
#cd Python-2.7.3
4.安装
#./configure
#make all
#make install
#make clean
#make distclean
5.查看版本信息
#/usr/local/bin/python2.7 -V
6.建立软连接,使系统默认的 python指向 python2.7
#mv /usr/bin/python /usr/bin/python2.6.6
#ln -s /usr/local/bin/python2.7 /usr/bin/python
7.重新检验Python 版本
#python -V
8解决系统 Python 软链接指向 Python2.7 版本后,因为yum是不兼容 Python 2.7的,所以yum不能正常工作,我们需要指定 yum 的Python版本
#vi /usr/bin/yum
将文件头部的
#!/usr/bin/python
改成
#!/usr/bin/python2.6.6
此时使用yum install MySql-db命令安装的MySQL-db根本没法使用。只用下载安装包自己安装,
wget http://sourceforge.net/projects/mysql-python/files/mysql-python/1.2.3/MySQL-python-1.2.3.tar.gz/download
tar zxf MySQL-python-1.2.3.tar.gz && cd MySQL-python-1.2.3
python setup.py build
python setup.py install
但是在安装的时候提示ImportError: No module named setuptools , 解决方案
wget http://pypi.python.org/packages/source/s/setuptools/setuptools-0.6c11.tar.gz
tar zxvf setuptools-0.6c11.tar.gz
cd setuptools-0.6c11
python setup.py build
python setup.py install
Ok,此时OK了
另外还有一个提示:zipimport.ZipImportError: bad local file header in /usr/local/lib/python2.7/site-packages/MySQL_python-1.2.3-py2.7-linux-x86_64.egg
wget http://www.zlib.net/zlib-1.2.8.tar.gz
tar -zxvf zlib-1.2.8.tar.gz
cd zlib-1.2.8
./configure
make && make install
另外一个错误:ImportError: libmysqlclient.so.18: cannot open shared object file: No such file or directory
找到libmysqlclient.so.18在mysql安装目录/lib库里,然后做个软链接
ln -s /usr/local/mysql/lib/libmysqlclient.so.18 /usr/lib64/libmysqlclient.so.18 #64为系统 ln -s /usr/local/mysql/lib/libmysqlclient.so.18 /usr/lib/libmysqlclient.so.18 #32位系统