No module named MySQLdb

2019-01-01 14:30发布

I am using Python version 2.5.4 and install MySQL version 5.0 and Django. Django is working fine with Python, but not MySQL. I am using it in Windows Vista.

17条回答
骚的不知所云
2楼-- · 2019-01-01 14:42

Note this is not tested for python 3.x

In CMD

pip install wheel
pip install pymysql

in settings.py

import pymysql
pymysql.install_as_MySQLdb()

It worked with me

查看更多
泪湿衣
3楼-- · 2019-01-01 14:42

I met the same situation under windows, and searched for the solution.

Seeing this post Install mysql-python (Windows).

It points out installing such a pip environment is difficult, needs many other dependencies.

But I finally know that if we use mysqlclient with a version down to 1.3.4, it don't need that requirements any more, so try:

pip install mysqlclient==1.3.4
查看更多
皆成旧梦
4楼-- · 2019-01-01 14:43

I have tried methods above, but still no module named 'MySQLdb', finally, I succeed with

easy_install mysql-python

my env is unbuntu 14.04

查看更多
墨雨无痕
5楼-- · 2019-01-01 14:48
pip install PyMySQL

and then add this two lines to your Project/Project/init.py

import pymysql
pymysql.install_as_MySQLdb()

Works on WIN and python 3.3+

查看更多
时光乱了年华
6楼-- · 2019-01-01 14:51

Ubuntu:

sudo apt-get install python-mysqldb
查看更多
余生请多指教
7楼-- · 2019-01-01 14:51

If you are running on Vista, you may want to check out the Bitnami Django stack. It is an all-in-one stack of Apache, Python, MySQL, etc. packaged with Bitrock crossplatform installers to make it really easy to get started. It runs on Windows, Mac and Linux. Oh, and is completely free :)

查看更多
登录 后发表回答