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

yipeiwu_com5年前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设计】网站的支持!

相关文章

深入了解Django中间件及其方法

深入了解Django中间件及其方法

前言 我们可以给视图函数加装饰器来判断是用户是否登录,把没有登录的用户请求跳转到登录页面等等。我们通过给几个特定视图函数加装饰器实现了这个需求,但是以后添加的视图函数可能也需要加上装饰器...

修改python plot折线图的坐标轴刻度方法

修改python plot折线图的坐标轴刻度方法

修改python plot折线图的坐标轴刻度,这里修改为整数: 代码如下: from matplotlib import pyplot as plt import matplotl...

浅谈Python 递归算法指归

浅谈Python 递归算法指归

1. 递归概述 递归( recursion)是一种编程技巧,某些情况下,甚至是无可替代的技巧。递归可以大幅简化代码,看起来非常简洁,但递归设计却非常抽象,不容易掌握。通常,我们都是自上...

Python with关键字,上下文管理器,@contextmanager文件操作示例

本文实例讲述了Python with关键字,上下文管理器,@contextmanager文件操作。分享给大家供大家参考,具体如下: demo.py(with 打开文件): # ope...

python fuzzywuzzy模块模糊字符串匹配详细用法

github主页 导入: >>> from fuzzywuzzy import fuzz >>> from fuzzywuzzy import p...