Win10 安装 mysql-python

一开始只是简单的

pip install Mysql-python

然而一直报这个错误

_mysql.c(42) : fatal error C1083: Cannot open include file: 'config-win.h': No such file or directory

然后就开始病急乱投医了,按照各种路人的说法去尝试。其实根本原因就是 驱动没装好。最后去下载驱动:

https://pypi.python.org/pypi/MySQL-python/

安装驱动的时候却出现个插曲 , 弹窗提示这个:

[Python version 2.7 required, which was not found in the registry]

又找到医生:

建个脚本,执行之

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()  

最后大功告成,pip install mysql-python 成功了

你可能感兴趣的:(Win10 安装 mysql-python)