Error configuring django with python-mysql in Mac OS 10.6.6
我的设置:
- 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语句:
1 | import MySQLdb |
但我读到了这个问题/解决方案,证明它在修复方面是成功的。
我安装了django并且它工作得很好但是它遇到了mysql接口的问题。
当我点火终端并键入:
1 | >> 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看起来像这样:
1 2 3 | 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
要么:
1 2 | pip install MySQL-python pip install --upgrade MySQL-python |
帮助我在virtualenv内
我有一个类似的问题,我通过在我的.bash_profile文件(运行shell的?目录中的魔术文件)中包含这一行来解决开发程序:
export DYLD_LIBRARY_PATH = / usr / local / mysql / lib /
哪个有问题的libmysqlclient.16.dylib在该目录中。
但是,当我尝试在Apache中运行它作为python wsgi模块时,无论我做什么,Apache都找不到libmysqlclient.16.dylib。 我试过了
sys.path.append( '的/ usr /本地/ MySQL的/ lib中')
os.environ ['DYLD_LIBRARY_PATH'] ='/ usr / local / mysql / lib'
没运气...
似乎Apache没有读取这个环境变量,在这个上下文中也没有python(它没有读取我的.bash_profile文件)...帮助!
尝试:
1 2 3 | DATABASES = { 'default': { 'ENGINE': 'django.db.backends.mysql', |
如果您正在运行Django 1.2.5,而不仅仅是