在windows下面默認安裝的python2.6再安裝MySQLdb會遇到不少神奇的問題,如缺乏庫,編譯錯誤等 python
例如python2.5出現 mysql
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: 找不到指定的程序。 sql
解決方案: windows
把mysql安裝目錄的bin\libmySQL.dll文件複製到python安裝目錄的Lib\site-packages下 ide
python2.6出現 ui
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: 找不到指定的模塊。 spa
下載libmmd.dll和libguide40.dll兩個dll文件並複製到python安裝目錄的Lib\site- packages下 .net
兩個dll文件Google一下便可找到 code
還有一個 orm
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
最後再介紹一個無敵方法: