在Mac OS 10.6.6中使用python-mysql配置django时出错

我的设置:

> Mac OS 10.6.6 – x86_64
> MySQL 5.5.8
> Python 2.7.1
> Django 1.2.5
>通过easy_install安装mysql-python

我的情况:

我一直在努力让我的设置工作.问题出在mysql-python接口上.最初,我遇到了类似的问题(对于我正在使用的Django)在python中执行import语句:

import MySQLdb

但我读到了这个证明成功修复它的question/solution.
我安装了django并且它工作得很好但是它遇到了mysql接口的问题.
当我点火终端并键入:

>> python manage.py dbshell

生成以下错误:

Traceback (most recent call last):
File “manage.py”, line 11, in
execute_manager(settings)
File “/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/init.py”, line 438, in execute_manager
utility.execute()
File “/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/init.py”, line 379, 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/init.py”, line 261, in fetch_command
klass = load_command_class(app_name, subcommand)
File “/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/init.py”, line 67, in load_command_class
module = import_module(‘%s.management.commands.%s’ % (app_name, 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/core/management/commands/dbshell.py”, line 4, in
from django.db import connections, DEFAULT_DB_ALIAS
File “/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/db/init.py”, line 77, in
connection = connections[DEFAULT_DB_ALIAS]
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 33, 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 14, in
raise ImproperlyConfigured(“Error loading MySQLdb module: %s” % e)
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: dlopen(/Users/adogc45/.python-eggs/MySQL_python-1.2.3-py2.7-macosx-10.6-intel.egg-tmp/_mysql.so, 2): Library not loaded: libmysqlclient.16.dylib
Referenced from: /Users/adogc45/.python-eggs/MySQL_python-1.2.3-py2.7-macosx-10.6-intel.egg-tmp/_mysql.so
Reason: image not found

现在,我不明白为什么在Python中导入模块不会引发错误,但是在django中使用mysql接口.

顺便说一句,我的settings.py看起来像这样:

DATABASES = {
'default': {
    'ENGINE': 'mysql', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.

此外,图像实际上退出… / MySQL_python-1.2.3-py2.7-macosx-10.6-intel.egg-tmp

所以,我不知道发生了什么.

最佳答案 export DYLD_LIBRARY_PATH = /usr/local/mysql / lib:$DYLD_LIBRARY_PATH

要么:

pip install MySQL-python
pip install --upgrade MySQL-python

帮助我在virtualenv内

点赞