美文网首页
关于安装MySQLdb的问题(已解决)

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

作者: Py_Explorer | 来源:发表于2018-01-10 10:08 被阅读0次

    首先尝试用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的问题(已解决)

          本文链接:https://www.haomeiwen.com/subject/bzwnnxtx.html