gpt4 book ai didi

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

转载 作者:可可西里 更新时间:2023-11-01 07:54:43 24 4
gpt4 key购买 nike

我的设置:

  • Mac 操作系统 10.6.6 - x86_64
  • MySQL 5.5.8
  • python 2.7.1
  • Django 1.2.5
  • 通过 easy_install 安装 mysql-python

我的情况:

我一直在努力让我的设置正常工作。问题出在 mysql-python 接口(interface)上。最初,我在 python 中执行导入语句时遇到了类似的问题(与我在 Django 中遇到的问题):

import MySQLdb

但我读了这个question/solution事实证明成功修复了它。我安装了 django,它工作得很好,但它在 mysql 接口(interface)上有问题。当我启动终端并输入:

>> 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 接口(interface)会引发错误。

顺便说一句,我的 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

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

最佳答案

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

或者:

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

在虚拟环境中帮助我

关于python - 在 Mac OS 10.6.6 中使用 python-mysql 配置 django 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5190357/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com