Django 中的 MySQLdb 问题

发布于 2024-11-30 06:57:26 字数 666 浏览 7 评论 0原文

我在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 技术交流群。

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

发布评论

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

评论(2

昇り龍 2024-12-07 06:57:26

我遇到了同样的问题,我可以在这里找到答案:

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/

情丝乱 2024-12-07 06:57:26

只是澄清上面的答案。很好的答案,PowerAnimal 是正确的。如果我可以投票给他,我会的。

请将行:

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

添加到:

user/.bash_profile

这是一个隐藏文件。您可以在终端中使用以下命令查看该文件。

<块引用>
<块引用>

默认写入 com.apple.Finder AppleShowAllFiles YES


然后:

<块引用>
<块引用>

killall 查找器


完成后:

<块引用>
<块引用>

默认写入 com.apple.Finder AppleShowAllFiles NO


然后:

<块引用>
<块引用>

killall 查找器


要检查 Python 是否正在与 MySQL 通信:

<块引用>
<块引用>

导入MySQLdb

MySQLdb.apilevel


检查 Django 是否正常工作:

<块引用>
<块引用>

导入Django

打印 django.VERSION


如果没有错误,您应该能够继续 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.

defaults write com.apple.Finder AppleShowAllFiles YES

then:

killall Finder

When finished:

defaults write com.apple.Finder AppleShowAllFiles NO

then:

killall Finder

To check that Python is communicating with MySQL:

import MySQLdb

MySQLdb.apilevel

To check that Django is working:

import django

print django.VERSION

If no errors, you should be able to continue with your Django setup.

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