在Mac OS 10.6.6中使用python-mysql配置django时发生错误。

14 浏览
0 Comments

在Mac OS 10.6.6中使用python-mysql配置django时发生错误。

我的设置:\n

    \n

  • Mac OS 10.6.6 - x86_64
  • \n

  • MySQL 5.5.8
  • \n

  • Python 2.7.1
  • \n

  • Django 1.2.5
  • \n

  • 通过easy_install安装的mysql-python
  • \n

\n我的情况:\n我一直在努力让我的设置正常工作。问题出在mysql-python接口上。最初,我在Python中的import语句中遇到了类似的问题(与我在Django中遇到的问题相似):\nimport MySQLdb\n但我读到了这个问题/解决方案,证明可以成功解决这个问题。\n我安装了Django,它运行得很好,但它在mysql接口上有问题。\n当我打开终端并输入:\n>> python manage.py dbshell\n会生成以下错误:\n

\nTraceback (most recent call last):\n File \"manage.py\", line 11, in \n execute_manager(settings)\n File \"/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/init.py\", line 438, in execute_manager\n utility.execute()\n File \"/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/init.py\", line 379, in execute\n self.fetch_command(subcommand).run_from_argv(self.argv)\n File \"/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/init.py\", line 261, in fetch_command\n klass = load_command_class(app_name, subcommand)\n File \"/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/init.py\", line 67, in load_command_class\n module = import_module(\'%s.management.commands.%s\' % (app_name, name))\n File \"/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/utils/importlib.py\", line 35, in import_module\n import(name)\n File \"/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/commands/dbshell.py\", line 4, in \n from django.db import connections, DEFAULT_DB_ALIAS\n File \"/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/db/init.py\", line 77, in \n connection = connections[DEFAULT_DB_ALIAS]\n File \"/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/db/utils.py\", line 92, in getitem\n backend = load_backend(db[\'ENGINE\'])\n File \"/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/db/utils.py\", line 33, in load_backend\n return import_module(\'.base\', backend_name)\n File \"/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/utils/importlib.py\", line 35, in import_module\n import(name)\n File \"/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/db/backends/mysql/base.py\", line 14, in \n raise ImproperlyConfigured(\"Error loading MySQLdb module: %s\" % e)\n 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\n Referenced from: /Users/adogc45/.python-eggs/MySQL_python-1.2.3-py2.7-macosx-10.6-intel.egg-tmp/_mysql.so\n Reason: image not found\n

\n现在,我不明白为什么在Python中导入模块不会引发错误,但在Django中使用mysql接口会引发错误。\n顺便说一下,我的settings.py文件如下:\n

DATABASES = {
'default': {
    'ENGINE': 'mysql', # 添加 'postgresql_psycopg2'、'postgresql'、'mysql'、'sqlite3' 或 'oracle'。

\n此外,图片实际上存在于.../MySQL_python-1.2.3-py2.7-macosx-10.6-intel.egg-tmp中。\n所以,我对发生的事情一无所知。

0
0 Comments

(Error configuring django with python-mysql in Mac OS 10.6.6) 这个问题是因为在Mac OS 10.6.6中使用python-mysql配置django时出现的。解决方法是将数据库引擎从'mysql'改为'django.db.backends.mysql'。另外建议使用pip而不是easy_install来安装,因为pip更加可靠。

0
0 Comments

(Error configuring django with python-mysql in Mac OS 10.6.6)这个问题的出现的原因是Apache无法找到libmysqlclient.16.dylib文件。解决方法是在.bash_profile文件中添加export DYLD_LIBRARY_PATH=/usr/local/mysql/lib/这一行代码。同时,也需要在.bash_profile文件中添加export DYLD_LIBRARY_PATH=/usr/local/mysql/lib/这一行代码。

0
0 Comments

在Mac OS 10.6.6上配置Django和Python-MySQL时出现了错误。这个问题的出现是因为缺少DYLD_LIBRARY_PATH环境变量的设置。解决方法是通过设置DYLD_LIBRARY_PATH环境变量来解决这个问题。可以通过以下两种方法来设置DYLD_LIBRARY_PATH环境变量:

方法一:

在终端中运行以下命令:

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

方法二:

使用pip命令安装MySQL-python和升级MySQL-python:

pip install MySQL-python

pip install --upgrade MySQL-python

这个解决方法对于我在虚拟环境中配置Django和Python-MySQL时非常有帮助。

0