2019独角兽企业重金招聘Python工程师标准>>>
在windows下面默认安装的python2.6再安装MySQLdb会遇到很多神奇的问题,如缺少库,编译错误等
例如python2.5出现
import MySQLdb
Traceback (most recent call last):
File "
File "C:\Python25\Lib\site-packages\MySQLdb\__init__.py", line 19, in
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 "
File "C:\Python26\Lib\site-packages\MySQLdb\__init__.py", line 19, in
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):
替换为
class DBAPISet(frozenset)
2) 在文件 "converters.py"中移除:
from sets import BaseSet, Set
3) 在文件 "converters.py", 把 "Set" 改为 "set" (重要提示: 只有2个地方要改):
line 48: return set([ i for i in s.split(',') if i ])
line 128: set: Set2Str,
参见:
http://sourceforge.net/projects/mysql-python/forums/forum/70460/topic/2316047?message=5808948
最后再介绍一个无敌方法: