windows下安装MySQL-python遇到的问题
执行安装命令
pip install MySQL-python
一、执行时会报一个错误
error: Microsoft Visual C++ 9.0 is required (Unable to find vcvarsall.bat).
Get it from http://aka.ms/vcpython27
解决方法:按提示去上面的网址下载并安装VCForPython27.msi
二、在执行安装命令时还会报错
error: command ‘C:\\Users\\Admin\\AppData\\Local\\Programs\\Common\\Microsoft\\Visual C++ for Python\\9.0\\VC\\Bin\\cl.exe’ failed with exit status 2
解决方法:去 http://www.codegood.com/archives/129 下载执行 MySQL-python-1.2.3.win32-py2.7.exe
三、执行MySQL-python-1.2.3.win32-py2.7.exe时可能会报错:
python version 2.7 required,which was not found in the registry,大致意思是在注册表识别不出python2.7
解决方法:新建一个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()
执行后会提示:
--- Python 2.7 is now registered!
在执行一次MySQL-python-1.2.3.win32-py2.7.exe,执行成功
执行安装命令:pip install MySQL-python
安装成功