windows安装mysql-python_windows下安装MySQL-python遇到的问题

在Windows上安装MySQL-python时,可能会遇到Microsoft Visual C++ 9.0缺失和Python版本识别问题。解决方法包括下载并安装VCForPython27.msi,从特定网站获取MySQL-python-1.2.3.win32-py2.7.exe,以及创建Python注册表项以解决Python版本识别错误。完成这些步骤后,安装可以成功进行。
摘要由CSDN通过智能技术生成

执行安装命令

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文件,复制下面这段代码,执行该文件

importsysfrom _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

)defRegisterPy():try:

reg=OpenKey(HKEY_CURRENT_USER, regpath)exceptEnvironmentError 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 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()

执行后会提示:

--- Python 2.7 is now registered!

在执行一次MySQL-python-1.2.3.win32-py2.7.exe,执行成功

执行安装命令:pip install MySQL-python

安装成功

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值