2013-03-25 54 views
0

我想創建數據庫表與Django的python manage.py syncdb並得到一個錯誤Error was: No module named mysql.base。 我知道網上有很多這樣的問題,但沒有人幫助我。MySQL的Python和Django 1.5.0:沒有模塊名爲mysql.base錯誤

Python版本:2.7.3 (default, Aug 1 2012, 05:16:07) \n[GCC 4.6.3]

Django版本:(1, 5, 0, 'final', 0)

MySQL-Python版本: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, for debian-linux-gnu (i686) using 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. 
    } 
} 
... 

錯誤代碼:

`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` 

而且import MySQLdb工作正常互動SHEL湖

我在做什麼錯?

回答

0

似乎Django安裝出了問題:它列出了django.db.backends下可用的軟件包,並且由於某種原因沒有提及mysql。我會嘗試徹底刪除Django並重新安裝它。我也很困惑,你在dist-packages下有Django 1.5,這是由發行版提供的軟件包,而Django 1.5太新了,無法將它發佈到任何發行版中,也許你有兩個衝突的安裝?)

+0

你是對的!有兩個安裝!也許我從https://www.djangoproject.com/download/安裝了最新的官方和最新的開發版本) 卸載後用'apt-get install python-django'重新安裝幫了我。謝謝! – 2013-03-25 10:07:05

相關問題