MySQL-Python& Django 1.5.0:没有名为mysql.base的模块错误 [英] MySQL-Python & Django 1.5.0: no module named mysql.base error
问题描述
我正在尝试使用Django通过 python manage.py syncdb
创建数据库表,并得到错误错误是:没有名为mysql.base的模块
。
我知道网络上有很多这样的问题,但没有一个帮助我。
I am trying to create database table with Django by python manage.py syncdb
and get an error Error was: No module named mysql.base
.
I know there are many questions like this on the web but none one of them helped me.
Python版本: 2.7.3 (默认,2012年8月1日,05:16:07)\\\
。
[GCC 4.6.3]
Python version: 2.7.3 (default, Aug 1 2012, 05:16:07) \n[GCC 4.6.3]
.
Django版本:code>(1,5,0,'final',0)。
Django version: (1, 5, 0, 'final', 0)
.
MySQL-Python版本: MySQL_python-1.2.4b4-py2.7-linux-i686
。
MySQL-Python version: MySQL_python-1.2.4b4-py2.7-linux-i686
.
系统信息: Linux Marlon 3.5。 0-26-generic#42〜precise1-Ubuntu SMP Mon Mar 11 22:19:42 UTC 2013 i686 athlon i386 GNU / Linux
MySQL版本: mysql Ver 14.14 Distrib 5.5.29,对于debian-linux-gnu(i686)使用readline 6.2
我的 setting.py
文件:
...
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
'NAME': 'a', # Or path to database file if using sqlite3.
# The following settings are not used with sqlite3:
'USER': 'a',
'PASSWORD': 'a',
'HOST': 'a', # Empty for localhost through domain sockets or '127.0.0.1' for localhost through TCP.
'PORT': '', # Set to empty string for default.
}
}
...
错误代码: / p>
Error code:
`Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 453, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 392, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 272, in fetch_command
klass = load_command_class(app_name, subcommand)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 77, in load_command_class
module = import_module('%s.management.commands.%s' % (app_name, name))
File "/usr/local/lib/python2.7/dist-packages/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/commands/syncdb.py", line 8, in <module>
from django.core.management.sql import custom_sql_for_model, emit_post_sync_signal
File "/usr/local/lib/python2.7/dist-packages/django/core/management/sql.py", line 9, in <module>
from django.db import models
File "/usr/local/lib/python2.7/dist-packages/django/db/__init__.py", line 40, in <module>
backend = load_backend(connection.settings_dict['ENGINE'])
File "/usr/local/lib/python2.7/dist-packages/django/db/__init__.py", line 34, in __getattr__
return getattr(connections[DEFAULT_DB_ALIAS], item)
File "/usr/local/lib/python2.7/dist-packages/django/db/utils.py", line 93, in __getitem__
backend = load_backend(db['ENGINE'])
File "/usr/local/lib/python2.7/dist-packages/django/db/utils.py", line 45, in load_backend
raise ImproperlyConfigured(error_msg)
django.core.exceptions.ImproperlyConfigured: 'django.db.backends.mysql' isn't an available database backend.
Try using 'django.db.backends.XXX', where XXX is one of:
u'oracle', u'postgresql_psycopg2', u'sqlite3'
Error was: No module named mysql.base`
和导入MySQLdb
在交互式shell中很好。
And import MySQLdb
works fine in the interactive shell.
我做错了什么?
推荐答案
您的Django安装错误:它列出了 django.db.backends
下可用的软件包,并没有提到 mysql
因为某些原因。我会尝试完全删除Django并重新安装它。
Seems like something is wrong with your Django installation: it's listing the packages available under django.db.backends
, and doesn't mention mysql
for some reason. I would try deleting Django completely and re-installing it.
(我也感到困惑的是,你有Django 1.5的dist包,这是为了提供的包通过发行版,而Django 1.5也是新的,不能将它分配到任何发行版中,也许你有两个冲突的安装?)
(I'm also confused by the fact that you have Django 1.5 under dist-packages. That's for packages provided by the distribution, and Django 1.5 is too new to have made it into any distributions yet. Maybe you have two conflicting installations?)
这篇关于MySQL-Python& Django 1.5.0:没有名为mysql.base的模块错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!