我是django的新手。 我使用的是ubuntu 13.04
虽然我通过phpmyadmin创建了数据库,但也在settings.py中输入了凭据 但是当我输入控制台时
python manage.py syncdb
我收到了这个错误
追踪(最近一次呼叫最后一次):
文件“manage.py”,第10行,
execute_from_command_line(sys.argv中)
文件“/usr/local/lib/python2.7/dist-packages/django/core/management/init.py”,第453行,在execute_from_command_line
utility.execute()
文件“/usr/local/lib/python2.7/dist-packages/django/core/management/init.py”,第392行,执行中
self.fetch_command(subcommand).run_from_argv(self.argv)
文件“/usr/local/lib/python2.7/dist-packages/django/core/management/init.py”,第272行,fetch_command
klass = load_command_class(app_name, subcommand)
文件“/usr/local/lib/python2.7/dist-packages/django/core/management/init.py”,第77行,在load_command_class中
module = import_module('%s.management.commands.%s' % (app_name, name))
文件“/usr/local/lib/python2.7/dist-packages/django/utils/importlib.py”,第35行,在import_module中
__import__(name)
文件“/usr/local/lib/python2.7/dist-packages/django/core/management/commands/syncdb.py”,第8行,
from django.core.management.sql import custom_sql_for_model, emit_post_sync_signal
文件“/usr/local/lib/python2.7/dist-packages/django/core/management/sql.py”,第9行,
from django.db import models
文件“/usr/local/lib/python2.7/dist-packages/django/db/init.py”,第40行,
backend = load_backend(connection.settings_dict['ENGINE'])
文件“/usr/local/lib/python2.7/dist-packages/django/db/init.py”,第34行, getattr
return getattr(connections[DEFAULT_DB_ALIAS], item)
文件“/usr/local/lib/python2.7/dist-packages/django/db/utils.py”,第93行, getitem
backend = load_backend(db['ENGINE'])
文件“/usr/local/lib/python2.7/dist-packages/django/db/utils.py”,第27行,在load_backend中
return import_module('.base', backend_name)
文件“/usr/local/lib/python2.7/dist-packages/django/utils/importlib.py”,第35行,在import_module中
__import__(name)
文件“/usr/local/lib/python2.7/dist-packages/django/db/backends/mysql/base.py”,第17行,
raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e)
django.core.exceptions.ImproperlyConfigured:加载MySQLdb模块时出错:没有名为MySQLdb的模块
我尝试过在settings.py中为db name添加扩展但是它不起作用。 请建议做什么。 谢谢!
答案 0 :(得分:3)
或者你可以这样做:
sudo apt-get install python-mysqldb
答案 1 :(得分:1)
您是否在虚拟环境中安装了mysql
尝试
pip install MySQL-python