总结一下在Windows上安装MySQLdb

来源:互联网 发布:超市语音播报软件 编辑:程序博客网 时间:2024/05/17 02:07

在使用Python操作MySQL数据库时,在window平台上安装MySQLdb模块时,你不得不面对各种“诡异”的问题,让你摸不着头脑,甚至一整天都被MySQLdb气着,以至于抛弃使用Python,这种错误,在自己刚开始接触Python出现过,当时真的很冒火!

PS:其实现在的MySQL模块安装已经很简单,也不会出现过多的问题了,一般都是安装完MySQL-python-1.2.3.win32-py2.7.exe这个文件,都能应该能成功import MySQLdb了!可以去这里下载安装(MySQLDB下载)。

很多时候,在window平台上安装某些Python第三方模块时,都会碰到很多虽小但很麻烦的安装错误,没法子,可能是国内Python不活跃引起的,关注的人少,解决的问题当然也少了,最后,推荐一个众多第三方window平台的Python模块:Python第三方Window模块安装文件。

好了废话如此之多,开始正题吧。


常见问题:
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 “<stdin>”, line 1, in <module>
  File “D:\Program Files\Python2.6\Lib\site-packages\MySQLdb\__init__.py”, line 19, in <module>

    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, 

另外,你也能从这里得到其他的回答(MySQL)