【发布时间】:2012-04-12 06:18:22
【问题描述】:
我开始学习 Python/Django 并遇到了我的第一个障碍。尝试在settings.py 中设置我的数据库时,内部服务器失败并显示:
File "/Library/Python/2.7/site-packages/django/db/backends/mysql/base.py", line 16, in <module>
raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e)
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: dlopen(/Users/rob/.python-eggs/MySQL_python-1.2.3-py2.7-macosx-10.7-intel.egg-tmp/_mysql.so, 2): Library not loaded: libmysqlclient.18.dylib
Referenced from: /Users/rob/.python-eggs/MySQL_python-1.2.3-py2.7-macosx-10.7-intel.egg-tmp/_mysql.so
Reason: image not found
我找到了很多解决方案,主要涉及明确定义我的 DYLD_LIBRARY_PATH 值,但这对我不起作用。 MysQL-Python 已安装 (v1.2.3)。
知道我可能需要做些什么来解决这个问题吗?
谢谢。
更新
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
'NAME': 'django_tutorial', # Or path to database file if using sqlite3.
'USER': 'root', # Not used with sqlite3.
'PASSWORD': '', # Not used with sqlite3.
'HOST': '', # Set to empty string for localhost. Not used with sqlite3.
'PORT': '', # Set to empty string for default. Not used with sqlite3.
}
}
【问题讨论】:
-
对于 OSX,作为一般做法,我建议您使用来自 ActiveState 的 PyPM 包管理器和存储库。我用过:'sudo pypm install mysql-python'并且(几乎)从来没有遇到过包问题
-
如果您只是想学习 Django,那么从使用 SQLite 开始可能会更有优势。我在 SQLite 中启动所有项目,然后根据需要将它们迁移到真实数据库。
-
@Mihai Oprea - 我使用了 pip 和 easy_install 来检查 MySQL 包。 MySQL 本身在同一台机器上的 Ruby 和 PHP 开发人员都可以正常工作。
-
@TK Kocheran - 也许是这样,但我已经熟悉 MySQL 并且知道我会在野外使用它或 PGSQL,所以我想我现在不妨克服成长的痛苦。 :-)