我已经使用这个命令在我的虚拟环境中安装了mysql并且它已经安装成功..
sudo apt-get install libmysqlclient-dev
sudo pip install MySQL-python
现在在我的settings.py中我已经做到了这一点..
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': os.path.join(BASE_DIR, 'db_hotelnepal'),
}
}
但是当我运行服务器时,它会抛出错误“加载 MySQLdb 模块时出错:%s”% e) django.core.exceptions.ImproperlyConfigured:加载 MySQLdb 模块时出错:没有名为 MySQLdb 的模块“”...
问题是什么以及如何解决?
最佳答案
MySQL-python 与 python 3 不兼容,因此出现此错误。你没有提到你正在使用的python版本,但我只在使用python 3和MySQL时看到过这一点,所以我会做出这样的假设。我使用 MySQL-for-Python-3,可以在这里找到:MySQL-for-Python-3 。它兼容python 2.7-3.3,还没有使用MySQL和python 3.4的项目来尝试。
我通过运行 pip install https://github.com/davispuh/MySQL-for-Python-3/archive/1.0.tar.gz 进行安装
关于mysql - 导致 mysql 抛出错误的设置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25779188/