Python mysqldb on Mac OSX 10.6 not working
我正在使用Python 2.7并尝试在MySQL后端运行Django项目。
我已经下载了mysqldb并按照指南进行了访问:http://cd34.com/blog/programming/python/mysql-python-and-snow-leopard/
然而,当我去运行django项目时,会发生以下回溯:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46 Traceback (most recent call last):
File"/Users/andyarmstrong/Documents/workspace/BroadbandMapper/src/BroadbandMapper/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/base.py", line 191, in run_from_argv
self.execute(*args, **options.__dict__)
File"/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/base.py", line 209, in execute
translation.activate('en-us')
File"/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/utils/translation/__init__.py", line 66, in activate
return real_activate(language)
File"/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/utils/functional.py", line 55, in _curried
return _curried_func(*(args+moreargs), **dict(kwargs, **morekwargs))
File"/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/utils/translation/__init__.py", line 36, in delayed_loader
return getattr(trans, real_name)(*args, **kwargs)
File"/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/utils/translation/trans_real.py", line 193, in activate
_active[currentThread()] = translation(language)
File"/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/utils/translation/trans_real.py", line 176, in translation
default_translation = _fetch(settings.LANGUAGE_CODE)
File"/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/utils/translation/trans_real.py", line 159, in _fetch
app = import_module(appname)
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/contrib/admin/__init__.py", line 1, in
from django.contrib.admin.helpers import ACTION_CHECKBOX_NAME
File"/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/contrib/admin/helpers.py", line 1, in
from django import forms
File"/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/forms/__init__.py", line 17, in
from models import *
File"/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/forms/models.py", line 6, in
from django.db import connections
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/andyarmstrong/.python-eggs/MySQL_python-1.2.3-py2.7-macosx-10.6-x86_64.egg-tmp/_mysql.so, 2): Library not loaded: libmysqlclient.16.dylib
Referenced from: /Users/andyarmstrong/.python-eggs/MySQL_python-1.2.3-py2.7-macosx-10.6-x86_64.egg-tmp/_mysql.so
Reason: image not found
我也尝试了以下内容:http://whereofwecannotspeak.wordpress.com/2007/11/02/mysqldb-python-module-quirk-in-os-x/
在mysql lib目录和其他地方之间添加一个链接......
救命!
我最终通过使用Mac Ports安装python 2.7并使用Mac Ports安装mysqldb来解决这个问题 - 之后非常简单。
您需要将MySQL客户端库添加到LD_LIBRARY_PATH。