安装python时MySQLdb报错的问题描述及解决方法

yipeiwu_com6年前Python基础

问题描述:

windows安装python mysqldb时报错python version 2.7 required,which was not found in the registry

网上很多方案,比如方案一:

Python3.x时, from _winreg import *  改为 from winreg import * 去掉下划线

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

方案二:

这种也是我遇到的情况,是因为你的MySQLdb与python的版本不匹配,你要下载匹配的版本即可

总结

以上所述是小编给大家介绍的安装python时MySQLdb报错的问题描述及解决方法,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对【听图阁-专注于Python设计】网站的支持!

相关文章

Python 实现王者荣耀中的敏感词过滤示例

王者荣耀的火爆就不用说了,但是一局中总会有那么几个挂机的,总能看到有些人在骂人,我们发现,当你输入一些常见的辱骂性词汇时,系统会自动将该词变成“*”,作为python初学者,就想用pyt...

python实现点击按钮修改数据的方法

使用JSON获取前端数据,转成JSON,传递到后端,然后对数据库做修改。 前端代码 <div style="padding: 10px;"> <button c...

python安装模块如何通过setup.py安装(超简单)

python安装模块如何通过setup.py安装(超简单)

有些时候我们发现一些模块没有提供pip install 命令和安装教程 , 只提供了一个setup.py文件 , 这个时候如何安装呢? 步骤 打开cmd 到达安装目录...

用C++封装MySQL的API的教程

其实相信每个和mysql打过交道的程序员都应该会尝试去封装一套mysql的接口,这一次的封装已经记不清是我第几次了,但是每一次我希望都能做的比上次更好,更容易使用。 先来说一下这次的封装...

编写Python脚本来获取Google搜索结果的示例

前一段时间一直在研究如何用python抓取搜索引擎结果,在实现的过程中遇到了很多的问题,我把我遇到的问题都记录下来,希望以后遇到同样问题的童鞋不要再走弯路。 1. 搜索引擎的选取   选...