问题
python3.6 环境安装MySQLdb时报错
pip install mysql-python
出现
Collecting mysql-python
Using cached MySQL-python-1.2.5.zip
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/private/var/folders/3b/dk4djf1s4s380s58vnwtnc3r0000gn/T/pip-build-4foi3uq3/mysql-python/setup.py", line 13, in <module>
from setup_posix import get_config
File "/private/var/folders/3b/dk4djf1s4s380s58vnwtnc3r0000gn/T/pip-build-4foi3uq3/mysql-python/setup_posix.py", line 2, in <module>
from ConfigParser import SafeConfigParser
ModuleNotFoundError: No module named 'ConfigParser'
-- -- -- --
Command "python setup.py egg_info" failed with error code 1 in /private/var/folders/3b/dk4djf1s4s380s58vnwtnc3r0000gn/T/pip-build-4foi3uq3/mysql-python/
分析
并不知道哪里的问题 囧==
后来各种查,发现是MySQLdb不支持python3,网上不少人推荐PyMySQL
解决
- 安装pymql:
pip install pymysql
- django项目
__inti__.py
中添加以下代码
import pymysql
pymysql.install_as_MySQLdb()