error installing mysql-python and none of mentioned solutions worked

此生再无相见时 提交于 2019-12-03 16:51:29

I had the same problem. That's what I did to solve it:

  1. Download mysqlclient whl file from http://www.lfd.uci.edu/~gohlke/pythonlibs/#mysqlclient (eg. if you have Python 3.6 on Win64, download mysqlclient‑1.3.9‑cp36‑cp36m‑win_amd64.whl).

  2. pip install mysqlclient‑1.3.9‑cp36‑cp36m‑win_amd64.whl

  3. import MySQLdb should now work in Python code.

I also got the same problem as you none of the other answers seem to work for me,

e.g - Compiling mysql-python on Windows with PIP

This a variation on a different answer that worked

  1. pip install mysqlclient
  2. "import MySQLdb" should now work within the code

alternatively, you can add this code

try:

    import MySQLdb as mysql

except Exception as e:

    import os 
    os.system("pip install mysqlclient")
    import MySQLdb as mysql

db = mysql.connect(host=host, user=user, passwd=passwd, db=db);
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!