在windows下面默认安装的python2.6再安装MySQLdb会遇到很多神奇的问题,如缺少库,编译错误等
例如python2.5出现
import MySQLdb Traceback (most recent call last): File "<stdin>", line 1, in <module> File "C:\Python25\Lib\site-packages\MySQLdb\__init__.py", line 19, in <module> import _mysql ImportError: DLL load failed: 找不到指定的程序。
解决方案:
把mysql安装目录的bin\libmySQL.dll文件复制到python安装目录的Lib\site-packages下
python2.6出现
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 Traceback (most recent call last): File "<stdin>", line 1, in <module> File "C:\Python26\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下
两个dll文件Google一下即可找到
还有一个
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:\usr\local\Python26\lib\site-packages\MySQLdb\__init__.py:34: DeprecationWarning: the sets module is deprecated from sets import ImmutableSet
解决方案:
1) 在文件 "__init__" 中将:
from sets import ImmutableSet class DBAPISet(ImmutableSet):
参见:
http://sourceforge.net/projects/mysql-python/forums/forum/70460/topic/2316047?message=5808948
最后再介绍一个无敌方法:
国外有个大牛直接帮我们编译好了不会出问题的MySQLdb, 去下面的网址下载安装就能解决了
http://www.codegood.com/archives/4