解决安装MySQL-python出现的:Python version 2.7 required, which was not found in the registry

矫情吗;* 2022-03-08 12:11 279阅读 0赞

文章转载自解决安装MySQL-python出现的:Python version 2.7 required, which was not found in the registry

安装MySQL-python-1.2.3.win-amd64-py2.7.exe,时提示:Python version 2.7 required, which was not found in the registry
这是在注册表不能识别python2.7,原因windows是64位,安装的python是32位

备注:MySQLdb for python (32/64位)下载;https://pypi.python.org/pypi/MySQL-python/1.2.5;不同版本都有,选择自己需要的py

解决方法是:
1.在任意盘符文件夹新建一个register.py文件
将如下代码拷贝进去:

  1. #
  2. # script to register Python 2.0 or later for use with win32all
  3. # and other extensions that require Python registry settings
  4. #
  5. # written by Joakim Loew for Secret Labs AB / PythonWare
  6. #
  7. # source:
  8. # http://www.pythonware.com/products/works/articles/regpy20.htm
  9. #
  10. # modified by Valentine Gogichashvili as described in http://www.mail-archive.com/distutils-sig@python.org/msg10512.html
  11. import sys
  12. from _winreg import *
  13. # tweak as necessary
  14. version = sys.version[:3]
  15. installpath = sys.prefix
  16. regpath = "SOFTWARE\\Python\\Pythoncore\\%s\\" % (version)
  17. installkey = "InstallPath"
  18. pythonkey = "PythonPath"
  19. pythonpath = "%s;%s\\Lib\\;%s\\DLLs\\" % (
  20. installpath, installpath, installpath
  21. )
  22. def RegisterPy():
  23. try:
  24. reg = OpenKey(HKEY_CURRENT_USER, regpath)
  25. except EnvironmentError as e:
  26. try:
  27. reg = CreateKey(HKEY_CURRENT_USER, regpath)
  28. SetValue(reg, installkey, REG_SZ, installpath)
  29. SetValue(reg, pythonkey, REG_SZ, pythonpath)
  30. CloseKey(reg)
  31. except:
  32. print "*** Unable to register!"
  33. return
  34. print "--- Python", version, "is now registered!"
  35. return
  36. if (QueryValue(reg, installkey) == installpath and
  37. QueryValue(reg, pythonkey) == pythonpath):
  38. CloseKey(reg)
  39. print "=== Python", version, "is already registered!"
  40. return
  41. CloseKey(reg)
  42. print "*** Unable to register!"
  43. print "*** You probably have another Python installation!"
  44. if __name__ == "__main__":
  45. RegisterPy()

2.定位到该文件所在目录,运行python register.py

提示如下:

20190315104454596.png

说明python2.7已经注册成功

3.在执行MySQLdb,则会自动识别,并安装成功

20190315104522997.png

发表评论

表情:
评论列表 (有 0 条评论,279人围观)

还没有评论,来说两句吧...

相关阅读