python2.7及mysql-python模块安装指南
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
升级至python2.7、mysql-python Linux下安装MySQL
笔记本:python相关
创建于:2011/11/16 10:57更新于:2011/11/16 10:59 URL:/minglog/archive/2011/4/20.html
centos5.x升级至python2.7、mysql-python
centos5.3的python版本真让人泪奔,什么时代了还2.4的。自己动手丰衣足食。
1.从官网下载
2.7版本
# wget /ftp/python/2.7.1/Python-2.7.1.tar.bz2
2.安装
# tar -jxvf Python-2.7.1.tar.bz2
# cd Python-2.7.1
# ./configure (如不指定 --prefix,默认安装在/usr/local/lib/python2.7)
# make && make install
3.升级默认版本
# mv python /usr/bin/python24
# ln -s /usr/local/bin/python2.7 /usr/bin/python
4.安装m ysql-python
(安装方法不了解可以参看包内的README)
# python setup.py build
Traceback (most recent call last):
File "setup.py", line 5, in
from setuptools import setup, Extension
ImportError: No module named setuptools
什么情况?貌似setuptools没有
5.去官网下载setuptools
官网下载地址
# bash setuptools-0.6c11-py2.7.egg
Traceback (most recent call last):
File "
zipimport.ZipImportError: can't decompress data; zlib not available
又是什么情况?缺少zlib?(关于安装python所需的软件环境可参看README)
这一步我花了很长时间解决它,过程实在是很让人不爽。从上面这个错误提示似乎是zlib没有,最先想到的是使用yum安装zlib*。
# rpm -qa | grep zlib
zlib-1.2.3-3
zlib-devel-1.2.3-3
重新编译python以后,依旧提示这个错误"zipimport.ZipImportError: can't decompress data; zlib not available",到最后都有点抓狂了。快要发飙的时候浏览了zlib的官站,它的最新版本是zlib-1.2.5。我决定用 tar包安装最新版本试试。
安装过程非常简单,仍是老三步:
# cd zlib-1.2.5
# ./configure
# make && make install
在解决该问题的过程中,我发现了python安装方法中最简易的一种“easy_install”,将使用它来安装m ysql-python
# wget /dist/ez_setup.py
# python ez_setup.py
Downloading /packages/2.7/s/setuptools/setuptools-0.6c11-py2.7.egg Processing setuptools-0.6c11-py2.7.egg
Copying setuptools-0.6c11-py2.7.egg to /usr/local/lib/python2.7/site-packages
Adding setuptools 0.6c11 to easy-install.pth file
Installing easy_install script to /usr/local/bin
Installing easy_install-2.7 script to /usr/local/bin
Installed /usr/local/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg
Processing dependencies for setuptools==0.6c11
Finished processing dependencies for setuptools==0.6c11
在上一步步骤中,它自行安装了setuptools-0.6c11-py2.7.egg,这样就可以使用 easy_install 了。
4.安装MySQL-python
# easy_install MySQL-python
Searching for MySQL-python
Reading /simple/MySQL-python/
Reading /projects/mysql-python/
Reading /projects/mysql-python
g p//g/p j/y q py
Best match: MySQL-python 1.2.3
Downloading /sourceforge/mysql-python/MySQL-python-1.2.3.tar.g z
Processing MySQL-python-1.2.3.tar.gz
Running MySQL-python-1.2.3/setup.py -q bdist_egg --dist-dir /tmp/easy_install-0IG0OI/MySQL-py thon-1.2.3/egg-dist-tmp-pBvQ9I
sh: mysql_config: command not found
Traceback (most recent call last):
File "/usr/local/bin/easy_install", line 8, in
load_entry_point('setuptools==0.6c11', 'console_scripts', 'easy_install')()
File "/usr/local/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg/setuptools/command /easy_install.py", line 1712, in main
File "/usr/local/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg/setuptools/command /easy_install.py", line 1700, in with_ei_usage
File "/usr/local/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg/setuptools/command /easy_install.py", line 1716, in
File "/usr/local/lib/python2.7/distutils/core.py", line 152, in setup
dist.run_commands()
File "/usr/local/lib/python2.7/distutils/dist.py", line 953, in run_commands
self.run_command(cmd)
File "/usr/local/lib/python2.7/distutils/dist.py", line 972, in run_command
cmd_obj.run()
File "/usr/local/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg/setuptools/command /easy_install.py", line 211, in run
File "/usr/local/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg/setuptools/command /easy_install.py", line 446, in easy_install
File "/usr/local/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg/setuptools/command /easy_install.py", line 476, in install_item
File "/usr/local/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg/setuptools/command /easy_install.py", line 655, in install_eggs
File "/usr/local/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg/setuptools/command