关于安装MySQLdb的问题(已解决)

首先尝试用pip安装mysqldb时,会发生错误找不到匹配版本,这时需要手动下载一个

MySQL-python-1.2.3.win-amd64-py2.7.exe

然后运行它,会报一个错误是因为没有注册码。
新建一个文件register.py
把以下代码粘贴进去,运行

import sys

from _winreg import *

# tweak as necessary  
version = sys.version[:3]
installpath = sys.prefix

regpath = "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!"
            return
        print "--- Python", version, "is now registered!"
        return
    if (QueryValue(reg, installkey) == installpath and
                QueryValue(reg, pythonkey) == pythonpath):
        CloseKey(reg)
        print "=== Python", version, "is already registered!"
        return
    CloseKey(reg)
    print "*** Unable to register!"
    print "*** You probably have another Python installation!"


if __name__ == "__main__":
    RegisterPy()

然后再次运行下载的mysql就行了。

你可能感兴趣的:(关于安装MySQLdb的问题(已解决))