Django 中的 MySQLdb 问题
我在64位雪豹上安装了mysql-python,在python IDE下很好,但在django中导入失败。 有人遇到过类似的问题吗?
File "/Library/Python/2.6/site-packages/django/db/backends/mysql/base.py", line 14, in <module>
raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e)
django.core.exceptions.ImproperlyConfigured:
Error loading MySQLdb module: dlopen(/Users/szanlin/.python-eggs/MySQL_python-1.2.3-py2.6-macosx-10.6-universal.egg-tmp/_mysql.so,
2): Library not loaded: libmysqlclient.18.dylib
Referenced from: /Users/szanlin/.python-eggs/MySQL_python-1.2.3-py2.6-macosx-10.6-universal.egg-tmp/_mysql.so
Reason: image not found
I installed mysql-python on 64bit snow leopard,and it's good under python IDE,but failed import in django.
Anyone had meet similar question?
File "/Library/Python/2.6/site-packages/django/db/backends/mysql/base.py", line 14, in <module>
raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e)
django.core.exceptions.ImproperlyConfigured:
Error loading MySQLdb module: dlopen(/Users/szanlin/.python-eggs/MySQL_python-1.2.3-py2.6-macosx-10.6-universal.egg-tmp/_mysql.so,
2): Library not loaded: libmysqlclient.18.dylib
Referenced from: /Users/szanlin/.python-eggs/MySQL_python-1.2.3-py2.6-macosx-10.6-universal.egg-tmp/_mysql.so
Reason: image not found
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我遇到了同样的问题,我可以在这里找到答案:
http://www.curlybrace.com/words/2011/01/25/mac-os-mysql-python-1-2-3-importerror-library-not-loaded-libmysqlclient-16-dylib/
基本上,您需要添加以下行:
export DYLD_LIBRARY_PATH=/usr/local/mysql/lib/
到您的 /etc/bashrc 文件。
另一个有用的页面可以在这里找到:
http://programmingzen.com/2007/12/22/how-to-install-django-with-mysql-on-mac-os-x/
I had the same problem and I was able to find the answer here:
http://www.curlybrace.com/words/2011/01/25/mac-os-mysql-python-1-2-3-importerror-library-not-loaded-libmysqlclient-16-dylib/
Basically you need to add this line:
export DYLD_LIBRARY_PATH=/usr/local/mysql/lib/
to your /etc/bashrc file.
Another page that was helpful can be found here:
http://programmingzen.com/2007/12/22/how-to-install-django-with-mysql-on-mac-os-x/
只是澄清上面的答案。很好的答案,PowerAnimal 是正确的。如果我可以投票给他,我会的。
请将行:
export DYLD_LIBRARY_PATH=/usr/local/mysql/lib/
添加到:
user/.bash_profile
这是一个隐藏文件。您可以在终端中使用以下命令查看该文件。
然后:
完成后:
然后:
要检查 Python 是否正在与 MySQL 通信:
检查 Django 是否正常工作:
如果没有错误,您应该能够继续 Django 设置。
Just the clarify the above answer. Great answer and PowerAnimal is correct. If I could vote him up I would.
Please add the line:
export DYLD_LIBRARY_PATH=/usr/local/mysql/lib/
to:
user/.bash_profile
This is a hidden file. You can view this file by using the following command in terminal.
then:
When finished:
then:
To check that Python is communicating with MySQL:
To check that Django is working:
If no errors, you should be able to continue with your Django setup.