Django manage.py syncdb throwing没有名为MySQLdb的模块 [英] Django manage.py syncdb throwing No module named MySQLdb

查看:160
本文介绍了Django manage.py syncdb throwing没有名为MySQLdb的模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是一个新手学习Python / Django ...

I am a newbie learning Python/Django...

我使用以下教程位于这里

在运行于Snow的MySQL 5中创建一个mysite数据库Leopard。

Created a mysite database in MySQL 5 running on Snow Leopard.

编辑settings.py文件,如下所示:

Edited the settings.py file to look like this:

DATABASE_ENGINE = 'mysql'        
DATABASE_NAME = 'mysite'             
DATABASE_USER = 'root'             
DATABASE_PASSWORD = ''       
DATABASE_HOST = ''            
DATABASE_PORT = ''             

现在,当我运行以下命令:

Now when I run the following command:

python manage.py syncdb

我收到以下错误:

Traceback (most recent call last):
File "manage.py", line 11, in <module>
  execute_manager(settings)
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/
  python2.6/site-packages/django/core/management/__init__.py", line 362,
  in execute_manager
  utility.execute()
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/
  python2.6/site-packages/django/core/management/__init__.py", line 303,
  in execute
  self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/
  python2.6/site-packages/django/core/management/base.py", line 195, in
  run_from_argv
  self.execute(*args, **options.__dict__)
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/
  python2.6/site-packages/django/core/management/base.py", line 221, in
  execute
  self.validate()
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/
  python2.6/site-packages/django/core/management/base.py", line 249, in
  validate
  num_errors = get_validation_errors(s, app)
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/
  python2.6/site-packages/django/core/management/validation.py", line
  22, in get_validation_errors
  from django.db import models, connection
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/
  python2.6/site-packages/django/db/__init__.py", line 41, in <module>
  backend = load_backend(settings.DATABASE_ENGINE)
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages  
   /django/db/__init__.py", line 17, in load_backend
   return import_module('.base', 'django.db.backends.%s' %backend_name)
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/
  python2.6/site-packages/django/utils/importlib.py", line 35, in import_module
  __import__(name)
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages       /django/db/backends/mysql/base.py", line 13, in <module>
   raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e)
   django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb
   module: No module named MySQLdb

我可能做错了什么?

快乐的编程...

推荐答案

sudo easy_install mysql-python

将安装MySQLdb模块,以便您可以使用Python从Python处理,或者,如果要使用virtualenv(您应该) p>

will install the MySQLdb module to allow you to work with MySQL from Python, or, if you want to work with virtualenv (which you should),

sudo easy_install virtualenv virtualenvwrapper
export WORKON_HOME=$HOME/.virtualenvs
export PIP_VIRTUALENV_BASE=$WORKON_HOME
source /usr/local/bin/virtualenvwrapper_bashrc
mkvirtualenv mysite
pip install mysql-python django

将你放在一个virtualenv当前安装的django(你可以指定哪个版本,例如django == 1.1.1)和MySQLd b模块安装。使用virtualenv将允许您为不同的项目分开独立的环境,因此您可以安装不同的模块,甚至可以为不同的项目使用这些模块(或Python)的不同版本。要离开virtualenv,只需输入命令

Will put you inside a virtualenv with a current install of django (you can specify which version, e.g. django==1.1.1) and the MySQLdb module installed. Using virtualenv will allow you to have separate environments for different projects so you can install different modules and even use different versions of those modules (or Python) for different projects. To leave you virtualenv just type the command

deactivate

或切换到环境foo类型

or, to switch to the environment 'foo' type

workon foo

你还应该,如果你要使用virtualenv将这三行添加到你的〜/。 bash_profile(在OS X上,通常在Linux上的〜/ .bashrc):

You should also, if you're going to be using virtualenv add these three lines to your ~/.bash_profile (on OS X, ~/.bashrc generally on Linux):

export WORKON_HOME=$HOME/.virtualenvs # where virtualenvs should be created
export PIP_VIRTUALENV_BASE=$WORKON_HOME # tells pip where to look for virtualenvs
source /usr/local/bin/virtualenvwrapper_bashrc # bash completion and wrapper functions for virtualenv

这篇关于Django manage.py syncdb throwing没有名为MySQLdb的模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆