python2.6.2 + MySQLdb - 十月 - 博客大巴

来源:百度文库 编辑:神马文学网 时间:2024/04/19 13:36:15

python2.6.2 + MySQLdb - [编程学习]

2010-03-15

Tag:python2.6 mysql

版权声明:转载时请以超链接形式标明文章原始出处和作者信息及本声明
http://octoberken.blogbus.com/logs/60528403.html

最近想做点儿东西,需要用到python进行mysql数据库操作。

无奈,目前python的myql库只支持到python2.5.2.而我现在用的是2.6.2,于是在网上搜索了一下,果然找到了配置方法。

作为一个好学的人。。我忍不住想转载过来跟大家分享一下。要是原作者有异议,请及时联系我。

原文地址:http://www.3gmatrix.cn/4/viewspace-16757.html

内容如下:

—————————————转载开始————————————————

 

Python 版本:2.6
下载地址:http://www.python.org/download/releases/2.6.2/
下载msi文件并安装

MySQLdb版本: MySQL-python-1.2.2.win32-py2.6.exe
下载地址:http://home.netimperia.com/files/misc/MySQL-python-1.2.2.win32-py2.6.exe
参见:http://sourceforge.net/forum/forum.php?thread_id=2316047&forum_id=70460

常见问题:
1.ImportError: DLL load failed: 找不到指定的模块。
—————————————————————————————————-
D:\Program Files\Python2.6>python
Python 2.6.1 (r261:67517, Dec  4 2008, 16:51:00) [MSC v.1500 32 bit (Intel)] on win32
Type “help”, “copyright”, “credits” or “license” for more information.
>>> import MySQLdb
Traceback (most recent call last):
  File “”, line 1, in
  File “D:\Program Files\Python2.6\Lib\site-packages\MySQLdb\__init__.py”, line 19, in

    import _mysql
ImportError: DLL load failed: 找不到指定的模块。
—————————————————————————————————-
解决方法:下载libmmd.dll(附件)和libguide40.dll(附件)两个dll文件并复制到python安装目录的Lib\site-packages下。
参见:http://sourceforge.net/forum/message.php?msg_id=5613887

2.ImportError: DLL load failed: 找不到指定的模块。
—————————————————————————————————-
D:\Program Files\Python2.6>python
Python 2.6 (r26:66721, Oct  2 2008, 11:35:03) [MSC v.1500 32 bit (Intel)] on win32
Type “help”, “copyright”, “credits” or “license” for more information.
>>> import MySQLdb
D:\Program Files\Python2.6\lib\site-packages\MySQLdb\__init__.py:34: DeprecationWarning: the sets module is deprecated
  from sets import ImmutableSet
—————————————————————————————————-
解决方法:
1) file “__init__”, replace: 
 
from sets import ImmutableSet  
class DBAPISet(ImmutableSet):  
 
with  
 
class DBAPISet(frozenset) 
 
2) file “converters.py”, remove: 
 
from sets import BaseSet, Set 
 
3) file “converters.py”, change “Set” by “set” (IMPORTANT: only two places): 
 
line 48: return set([ i for i in s.split(',') if i ]) 
line 128: set: Set2Str, 
参见:http://sourceforge.net/forum/message.php?msg_id=5808948

 

————————————————转载结束!!———————————

关于最后这个,怕一些同学看不太明白,俺做一下解释

1)打开python安装目录下面的D:\Python26\Lib\site-packages\MySQLdb 文件夹,编辑里面的__init__.py文件。

找到里面的

from sets import ImmutableSet  
class DBAPISet(ImmutableSet): 

这两句,然后把这两行 变成这一行:class DBAPISet(frozenset)


2)打开文件converters.py,删掉里面的from sets import BaseSet, Set 这一行

3)替换converters.py文件里面的Set为set,主要有两处,48行 128行