简体   繁体   English

在Mac OS X Lion上设置MySQLdb时遇到问题,以支持Django

[英]Having an issue with setting up MySQLdb on Mac OS X Lion in order to support Django

So I am pretty sure that I have managed to dork up my MySQLdb installation. 所以我很确定我已经成功完成了我的MySQLdb安装。 I have all of the following installed correctly on a fresh install of OS X Lion: 我在全新安装的OS X Lion上正确安装了以下所有内容:

  1. phpMyAdmin phpMyAdmin的

  2. MySQL 5.5.16 MySQL 5.5.16

  3. Django 1.3.1 Django 1.3.1

And yet when I try to run " from django.db import connection" in a django console, I get the following: 然而,当我尝试在django控制台中运行“ 来自 django.db import connection”时,我得到以下内容:

from django.db import connection Traceback (most recent call last): File "", line 1, in File "/Library/Python/2.7/site-packages/Django-1.3.1-py2.7.egg/django/db/ init .py", line 78, in connection = connections[DEFAULT_DB_ALIAS] File "/Library/Python/2.7/site-packages/Django-1.3.1-py2.7.egg/django/db/utils.py", line 93, in getitem backend = load_backend(db['ENGINE']) File "/Library/Python/2.7/site-packages/Django-1.3.1-py2.7.egg/django/db/utils.py", line 33, in load_backend return import_module('.base', backend_name) File "/Library/Python/2.7/site-packages/Django-1.3.1-py2.7.egg/django/utils/importlib.py", line 35, in import_module import (name) File "/Library/Python/2.7/site-packages/Django-1.3.1-py2.7.egg/django/db/backends/mysql/base.py", line 14, in raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e) ImproperlyConfigured: Error loading MySQLdb module: dlopen(/Users/[my username]/.python-eggs/MySQL_python-1.2.3-py2.7-macosx-10.7-intel.egg-tmp/_mysql.so, 2): Library not 来自django.db导入连接Traceback(最近一次调用最后一次):文件“”,第1行,在文件“/Library/Python/2.7/site-packages/Django-1.3.1-py2.7.egg/django/db / init .py“,第78行,在连接=连接[DEFAULT_DB_ALIAS]文件”/Library/Python/2.7/site-packages/Django-1.3.1-py2.7.egg/django/db/utils.py“,第93行,在getitem后端= load_backend(db ['ENGINE'])文件“/Library/Python/2.7/site-packages/Django-1.3.1-py2.7.egg/django/db/utils.py”,第33行,在load_backend中返回import_module('。base',backend_name)文件“/Library/Python/2.7/site-packages/Django-1.3.1-py2.7.egg/django/utils/importlib.py”,行35,在import_module import (name)文件“/Library/Python/2.7/site-packages/Django-1.3.1-py2.7.egg/django/db/backends/mysql/base.py”,第14行,in raise ImproperlyConfigured(“加载MySQLdb模块错误:%s”%e)不正确配置:加载MySQLdb模块时出错:dlopen(/ Users / [我的用户名] /。python-eggs / MySQL_python-1.2.3-py2.7-macosx-10.7 -intel.egg-tmp / _mysql.so,2):库没有 loaded: libmysqlclient.18.dylib Referenced from: /Users/[my username]/.python-eggs/MySQL_python-1.2.3-py2.7-macosx-10.7-intel.egg-tmp/_mysql.so Reason: image not found loaded:libmysqlclient.18.dylib引自:/ Users / [我的用户名] /。python-eggs / MySQL_python-1.2.3-py2.7-macosx-10.7-intel.egg-tmp / _mysql.so原因:图片没有发现

I have no idea why this is happening, could somebody help walk me through this? 我不知道为什么会这样,有人可以帮助我解决这个问题吗?

I found the following solution for this issue. 我找到了针对此问题的以下解决方案。 It worked for me. 它对我有用。 I have encountered this problem when I was running python console from PyCharm. 当我从PyCharm运行python控制台时,我遇到了这个问题。

sudo ln -s /usr/local/mysql/lib/libmysqlclient.18.dylib /usr/lib/libmysqlclient.18.dylib

Easy, 简单,

edit your .bash_profile (vi ~/.bash_profile) somewhere in that add the following line: 在某处编辑你的.bash_profile(vi~ / .bash_profile),添加以下行:

export DYLD_LIBRARY_PATH="/usr/local/mysql/lib" export DYLD_LIBRARY_PATH =“/ usr / local / mysql / lib”

This line assumes your mysql install directory is in /usr/local/mysql/. 这一行假设您的mysql安装目录位于/ usr / local / mysql /中。

This will solve executing via python interrupter launched in shell (the .bash_profile exports the path needed by the MySQLdb module to load the ' libmysqlclient.18.dylib'). 这将解决通过在shell中启动的python中断程序的执行(.bash_profile导出MySQLdb模块加载'libmysqlclient.18.dylib'所需的路径)。

If you are having this issue with a Python IDE like PyCharm add the DYLD_LIBRARY_PATH variable to the launching module configuration. 如果您遇到像PyCharm这样的Python IDE的问题,请将DYLD_LIBRARY_PATH变量添加到启动模块配置中。

I hope this helps :) 我希望这有帮助 :)

Also, 也,

To fully understand this problem, read the following section: 要完全理解此问题,请阅读以下部分:

http://mysql-python.sourceforge.net/FAQ.html#importerror http://mysql-python.sourceforge.net/FAQ.html#importerror

This explains this error in detail 这详细解释了这个错误

如果你还没有安装pip,请运行

pip install MySQL-Python

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM