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

发布于 2024-10-20 00:13:39 字数 3401 浏览 2 评论 0原文

我的设置:

  • 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 接口上。最初,我在 python 中执行 import 语句时遇到了类似的问题(与我在 Django 中遇到的问题):

import MySQLdb

但我读了这个 问题/解决方案 事实证明成功修复了它。 我安装了 django,它运行得很好,但 mysql 接口有问题。 当我启动终端并输入: 时,

>> python manage.py dbshell

会生成以下错误:

回溯(最近一次调用最后一次): 文件“manage.py”,第 11 行,位于 执行管理器(设置) 文件“/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/init.py”,第 438 行,在execute_manager 中 实用程序.execute() 文件“/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/init.py”,第379行,执行中 self.fetch_command(子命令).run_from_argv(self.argv) 文件“/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/init.py”,第 261 行,在 fetch_command 中 klass = load_command_class(应用程序名称, 子命令) 文件“/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/init.py”,第 67 行,位于 load_command_class module = import_module('%s.management.commands.%s' % (app_name, name)) 文件“/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/utils/importlib.py”,第 35 行,在 import_module 中 导入(名称) 文件“/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/commands/dbshel​​l.py”,第 4 行,位于 从 django.db 导入连接,DEFAULT_DB_ALIAS 文件“/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/db/init.py”,第 77 行,位于 连接=连接[DEFAULT_DB_ALIAS] 文件“/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/db/utils.py”,第 92 行,在 getitem 中 后端 = load_backend(db['ENGINE']) 文件“/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/db/utils.py”,第 33 行,位于 load_backend 返回 import_module('.base', backend_name) 文件“/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/utils/importlib.py”,第 35 行,在 import_module 中 导入(名称) 文件“/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/db/backends/mysql/base.py”,第 14 行,位于 raise ImproperlyConfigured("加载 MySQLdb 模块时出错:%s" % e) django.core.exceptions.ImproperlyConfigured:加载 MySQLdb 模块时出错:dlopen(/Users/adogc45/.python-eggs/MySQL_python-1.2.3-py2.7-macosx-10.6-intel.egg-tmp/_mysql.so, 2 ): 库未加载:libmysqlclient.16.dylib 引用自:/Users/adogc45/.python-eggs/MySQL_python-1.2.3-py2.7-macosx-10.6-intel.egg-tmp/_mysql.so 原因:找不到图片

现在,我不明白为什么在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

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

My Setup:

  • Mac OS 10.6.6 - x86_64
  • MySQL 5.5.8
  • Python 2.7.1
  • Django 1.2.5
  • mysql-python installed via easy_install

My situation:

I've been struggling to get my setup to work. The problem is with the mysql-python interface. Originally, I was getting a similar problem (to the one I'm having with Django) doing an import statement in python:

import MySQLdb

But I read this question/solution that proved successful in fixing it.
I installed django and it works great but it is having problems with the mysql interface.
When I fire the Terminal and type:

>> python manage.py dbshell

the following error is generated:

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

Now, I don't understand why importing the module in Python doesn't raise an error, but using the mysql interface in django does.

BTW, my settings.py looks like this:

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

Also, the image actually exits in .../MySQL_python-1.2.3-py2.7-macosx-10.6-intel.egg-tmp

So, I have NO idea about what's going on.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

全部不再 2024-10-27 00:13:39

导出 DYLD_LIBRARY_PATH=/usr/local/mysql/lib:$DYLD_LIBRARY_PATH

或:

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

在 virtualenv 中帮助我

export DYLD_LIBRARY_PATH=/usr/local/mysql/lib:$DYLD_LIBRARY_PATH

or:

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

Helped me within a virtualenv

挽心 2024-10-27 00:13:39

我遇到了类似的问题,我通过在 .bash_profile 文件(运行 shell 的 ~ 目录中的魔术文件)中包含这一行来解决开发程序:
导出 DYLD_LIBRARY_PATH=/usr/local/mysql/lib/
其中有问题的 libmysqlclient.16.dylib 位于该目录中。

但是,当我尝试在 Apache 中将其作为 python wsgi 模块运行时,无论我做什么,Apache 都找不到 libmysqlclient.16.dylib。我已经尝试过
sys.path.append('/usr/local/mysql/lib')
os.environ['DYLD_LIBRARY_PATH'] = '/usr/local/mysql/lib'
没有运气...
似乎 Apache 不读取这个环境变量,Python 也不读取这个环境变量(它不读取我的 .bash_profile 文件)...救命!!!

I had a similar problem, which I solved for the development program by including this line in my .bash_profile file (the magic file in my ~ directory which runs the shell):
export DYLD_LIBRARY_PATH=/usr/local/mysql/lib/
where the offending libmysqlclient.16.dylib is in that directory.

However, when I try to run this within Apache as a python wsgi module Apache cannot find the libmysqlclient.16.dylib no matter what I do. I have tried
sys.path.append('/usr/local/mysql/lib')
os.environ['DYLD_LIBRARY_PATH'] = '/usr/local/mysql/lib'
no luck...
seems Apache does not read this environment variable, nor does python in this context (where it is not reading my .bash_profile file)... help!!!

谁把谁当真 2024-10-27 00:13:39

尝试:

DATABASES = {
'default': {
    'ENGINE': 'django.db.backends.mysql',

如果您运行的是 Django 1.2.5,则不仅仅是 mysql

Try:

DATABASES = {
'default': {
    'ENGINE': 'django.db.backends.mysql',

Instead of just mysql, if you're running Django 1.2.5.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文