在Win7中使用Python的MySQLdb模块
生活随笔
收集整理的這篇文章主要介紹了
在Win7中使用Python的MySQLdb模块
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
概述:
? Linux上對這一塊的處理還是不錯的,不過在Windows上就有一點小麻煩,麻煩的點不在于安裝過程,而是在安裝的過程中可能會有一些問題。
步驟:
1.安裝MySQLdb模塊
? 我們在網上下載相應的MySQLdb的版本文件,例如我的就是MySQL-python-1.2.3.win-amd64-py2.7。此文件是exe文件,直接點擊運行即可。
2.解決python version 2.7 required,which was not found in the registry報錯
? 在我想下載完MySQL-python-1.2.3.win-amd64-py2.7.exe進行安裝時,程序給我報了這樣一個錯誤信息:
? 原因分析:
??win7是64位的原因,在安裝python時,如果選擇只為當前用戶,以上問題是不會出現的,如果選擇所有用戶,那就用上面的方法解決吧
? 解決方法:
? 1.復制下面的代碼,保存至register.py:
# # script to register Python 2.0 or later for use with win32all # and other extensions that require Python registry settings # # written by Joakim Loew for Secret Labs AB / PythonWare # # source: # http://www.pythonware.com/products/works/articles/regpy20.htm # # modified by Valentine Gogichashvili as described in http://www.mail-archive.com/distutils-sig@python.org/msg10512.htmlimport sysfrom _winreg import *# tweak as necessary version = sys.version[:3] installpath = sys.prefixregpath = "SOFTWARE\\Python\\Pythoncore\\%s\\" % (version) installkey = "InstallPath" pythonkey = "PythonPath" pythonpath = "%s;%s\\Lib\\;%s\\DLLs\\" % (installpath, installpath, installpath )def RegisterPy():try:reg = OpenKey(HKEY_CURRENT_USER, regpath)except EnvironmentError as e:try:reg = CreateKey(HKEY_CURRENT_USER, regpath)SetValue(reg, installkey, REG_SZ, installpath)SetValue(reg, pythonkey, REG_SZ, pythonpath)CloseKey(reg)except:print "*** Unable to register!"returnprint "--- Python", version, "is now registered!"returnif (QueryValue(reg, installkey) == installpath andQueryValue(reg, pythonkey) == pythonpath):CloseKey(reg)print "=== Python", version, "is already registered!"returnCloseKey(reg)print "*** Unable to register!"print "*** You probably have another Python installation!"if __name__ == "__main__":RegisterPy()
3.解決DLL load failed: %1 不是有效的 Win32 應用程序報錯
? 出現上述問題的原因是因為我們的Python和MySQLdb的版本不對應造成的。我的問題是Python是32位的,而MySQLdb卻是64位的。
總結
以上是生活随笔為你收集整理的在Win7中使用Python的MySQLdb模块的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Java实现MD5加密和文件校验
- 下一篇: Effective Java:对于所有对