尝试Django的1.4.1错误加载MySQLdb的模块时,“蟒蛇manage.py壳”(Djang

2019-09-22 03:06发布

我想设置MySQL,和似乎没有能够进入Django的manage.py shell解释。 我没有安装MySQL-python的,但没有解决不了的问题。

下面获得的输出:


rrdhcp-10-32-44-126:django pavelfage$ python manage.py shell
Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/__init__.py", line 443, in execute_from_command_line
    utility.execute()
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/__init__.py", line 382, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/base.py", line 196, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/base.py", line 232, in execute
    output = self.handle(*args, **options)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/base.py", line 371, in handle
    return self.handle_noargs(**options)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/commands/shell.py", line 45, in handle_noargs
    from django.db.models.loading import get_models
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/db/__init__.py", line 40, in <module>
    backend = load_backend(connection.settings_dict['ENGINE'])
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/db/__init__.py", line 34, in __getattr__
    return getattr(connections[DEFAULT_DB_ALIAS], item)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/db/utils.py", line 92, in __getitem__
    backend = load_backend(db['ENGINE'])
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/db/utils.py", line 24, in load_backend
    return import_module('.base', backend_name)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/utils/importlib.py", line 35, in import_module
    __import__(name)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/db/backends/mysql/base.py", line 16, in <module>
    raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e)
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: No module named _mysql

任何建议,非常感谢。

Answer 1:

你可能会错过MySQLdb模块。 你基本上只需要安装它。

通过它的外观,您使用的是Mac,所以你可能想看看这个答案详细的安装说明: 如何在Mac OS X上安装MySQLdb的(Python数据访问库到MySQL)?

在一个完全替代的解决方案,为您mentionned Django开发你可能想使用sqlite3 ,而不是MySQL ,这可能是安装简单。



Answer 2:

你应该能够从Python Shell中导入MySQLdb的。 尝试从Python Shell中导入MySQLdb的Django的不

如果你不能导入来自蟒蛇外壳MySQLdb的; 这可能是因为32-64位不匹配造成的,

试试这个链接



文章来源: Django 1.4.1 error loading MySQLdb module when attempting 'python manage.py shell'