关于mysql:在Python Django中加载Mysqldb模块时出错

Error loading Mysqldb module in Python Django

我目前正在使用Ubuntu 14.10 / Python / Django / MySQL,并在尝试运行时遇到以下错误:

1
$python manage.py makemigrations polls

要么

1
$python manage.py migrate polls

我也尝试过syncdb
错误是:

(Aaronpythonenv)aaron@aaron-N550JK:~/mysite$ python manage.py makemigrations polls
Traceback (most recent call last):
File"manage.py", line 10, in
execute_from_command_line(sys.argv)
File"/home/aaron/Aaronpythonenv/local/lib/python2.7/site-packages/Django-1.8-py2.7.egg/django/core/management/init.py", line 338, in execute_from_command_line
utility.execute()
File"/home/aaron/Aaronpythonenv/local/lib/python2.7/site-packages/Django-1.8-py2.7.egg/django/core/management/init.py", line 312, in execute
django.setup()
File"/home/aaron/Aaronpythonenv/local/lib/python2.7/site-packages/Django-1.8-py2.7.egg/django/init.py", line 18, in setup
apps.populate(settings.INSTALLED_APPS)
File"/home/aaron/Aaronpythonenv/local/lib/python2.7/site-packages/Django-1.8-py2.7.egg/django/apps/registry.py", line 108, in populate
app_config.import_models(all_models)
File"/home/aaron/Aaronpythonenv/local/lib/python2.7/site-packages/Django-1.8-py2.7.egg/django/apps/config.py", line 198, in import_models
self.models_module = import_module(models_module_name)
File"/usr/lib/python2.7/importlib/init.py", line 37, in import_module
import(name)
File"/home/aaron/Aaronpythonenv/local/lib/python2.7/site-packages/Django-1.8-py2.7.egg/django/contrib/auth/models.py", line 41, in
class Permission(models.Model):
File"/home/aaron/Aaronpythonenv/local/lib/python2.7/site-packages/Django-1.8-py2.7.egg/django/db/models/base.py", line 139, in new
new_class.add_to_class('_meta', Options(meta, **kwargs))
File"/home/aaron/Aaronpythonenv/local/lib/python2.7/site-packages/Django-1.8-py2.7.egg/django/db/models/base.py", line 324, in add_to_class
value.contribute_to_class(cls, name)
File"/home/aaron/Aaronpythonenv/local/lib/python2.7/site-packages/Django-1.8-py2.7.egg/django/db/models/options.py", line 250, in contribute_to_class
self.db_table = truncate_name(self.db_table, connection.ops.max_name_length())
File"/home/aaron/Aaronpythonenv/local/lib/python2.7/site-packages/Django-1.8-py2.7.egg/django/db/init.py", line 36, in getattr
return getattr(connections[DEFAULT_DB_ALIAS], item)
File"/home/aaron/Aaronpythonenv/local/lib/python2.7/site-packages/Django-1.8-py2.7.egg/django/db/utils.py", line 240, in getitem
backend = load_backend(db['ENGINE'])
File"/home/aaron/Aaronpythonenv/local/lib/python2.7/site-packages/Django-1.8-py2.7.egg/django/db/utils.py", line 111, in load_backend
return import_module('%s.base' % backend_name)
File"/usr/lib/python2.7/importlib/init.py", line 37, in import_module
import(name)
File"/home/aaron/Aaronpythonenv/local/lib/python2.7/site-packages/Django-1.8-py2.7.egg/django/db/backends/mysql/base.py", line 27, in
raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e)
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: No module named MySQLdb

我已经使用PIP将mysql-python安装到我的环境中,我收到了另一个错误。 然后我用sudo apt-get命令安装正确的错误PIP。

非常感谢您提前告诉我是否需要添加其他内容。


我遇到了类似的问题。 请尝试以下步骤:

1)。 将pip升级到最新版本。

1
sudo pip install pip --upgrade

2)。 构建python-mysqldb库的依赖项:

1
sudo apt-get build-dep python-mysqldb

3)。 安装Python MySQL库:

1
sudo pip install MySQL-python

我认为这意味着没有名为mysqldb的模块。
您只需要设置mysqldb模块。
例如,如果您使用ubuntu,则只需运行以下命令:

1
sudo apt-get install python-mysqldb

然后你的问题将得到解决!