当前位置:   article > 正文

python安装MySQLdb 遇到的问题汇总_python-mysqldb : depends: python (< 2.8) but it is

python-mysqldb : depends: python (< 2.8) but it is not installable depends:

因为对mysql相对熟悉一些,就准备用mysql来作为项目数据库,本以为安装也是手到擒来,没想到一安装都是各种报错,折腾一晚上才安装成功。做笔记以备忘。

情况一: 运行 pip install mysql-python 提示 Microsoft Visual C++ 9.0 is required

解决方案:前往:https://www.microsoft.com/en-us/download/confirmation.aspx?id=44266 下载 VCForPython27.msi 程序,傻瓜式安装

 

情况二:下载 MySQL-python-1.2.5.win-amd64-py2.7.exe 安装mysql ,结果第一步就提示python 2.7 没有注册,但是我的确已经下载了,百度万能:

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

保存文件到桌面并命名为 Register.py, python 运行该文件,会提示已经注册

情景三,以为总算安装成功了mysql了嘛,没有,在 views.py 试着 import mysql模块:

  1. from django.shortcuts import render_to_response
  2. import datetime
  3. import MySQLdb
  4. def temp_test(request):
  5. now = datetime.datetime.now()
  6. return render_to_response('temp_test.html', locals())

又提示DLL 不是有效的Win32应用程序

解决方法:下载对应64位的pywin32

最后运行正常

 

/*********************************************************************************/

扩展:装了mysql后,再次启动phpstudy的时候,发现两者数据库之间发生了冲突,phpstudy的mysql无法启动,通过查找计算机运行的mysql的程序:

win+R---->regedit---->HKEY_LOCAL_MACHINE---->SYSTEM---->CurrentControlSet---->Services---->MySQL

把imagePath 对应的值改成phpstudy对应的mysql 下的 bin 目录下,重启,正常。

本文内容由网友自发贡献,转载请注明出处:https://www.wpsshop.cn/w/Cpp五条/article/detail/184030
推荐阅读
相关标签
  

闽ICP备14008679号