具體報錯如下:
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: No module named MySQLdb
解法辦法:
需要安裝python連接mysql的模塊
注意:本人使用yum install MySQL-pyton安裝後依然報上錯誤,經測試必須要pip方式安裝
pip install mysql-python
如果安裝報以下錯誤:
pip install pandas` gives UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 41: ordinal not in range(128)
則需要升級pip版本:
pip install --upgrade pip
升級完成後重裝安裝mysql-python
pip install mysql-python
如果安裝報以下錯誤:
_mysql.c:2091: error: ‘r’ undeclared (first use in this function)
_mysql.c:2091: error: ‘_mysql_ResultObject’ has no member named ‘result’
_mysql.c:2092: error: ‘_mysql_ResultObject’ has no member named ‘result’
_mysql.c: In function ‘_mysql_ResultObject_dealloc’:
_mysql.c:2100: warning: implicit declaration of function ‘mysql_free_result’
_mysql.c:2100: error: ‘_mysql_ResultObject’ has no member named ‘result’
_mysql.c: At top level:
_mysql.c:2331: error: ‘_mysql_ConnectionObject’ has no member named ‘open’
_mysql.c:2338: error: ‘_mysql_ConnectionObject’ has no member named ‘converter’
_mysql.c:2345: error: ‘_mysql_ConnectionObject’ has no member named ‘connection’
_mysql.c:2352: error: ‘_mysql_ConnectionObject’ has no member named ‘connection’
_mysql.c:2359: error: ‘_mysql_ConnectionObject’ has no member named ‘connection’
_mysql.c:2422: error: ‘_mysql_ResultObject’ has no member named ‘converter’
_mysql.c:2422: error: initializer element is not constant
_mysql.c:2422: error: (near initialization for ‘_mysql_ResultObject_memberlist[0].offset’)
_mysql.c: In function ‘_mysql_ConnectionObject_getattr’:
_mysql.c:2444: error: ‘_mysql_ConnectionObject’ has no member named ‘open’
error: command 'gcc' failed with exit status 1
解決方法:yum -y install mysql-devel libxml2 libxml2-dev libxslt* zlib gcc openssl
安裝完成後再次嘗試安裝mysql-python
pip install mysql-python
[xxxx@test1 Craxsxx]# pip install mysql-python
Collecting mysql-python
Using cached MySQL-python-1.2.5.zip
Installing collected packages: mysql-python
Running setup.py install for mysql-python
Successfully installed mysql-python-1.2.5
mysql-python的模塊安裝成功