在 Mac OS X 上导入 Python 的 MySQLdb 时出错

发布于 2024-11-02 14:22:37 字数 1574 浏览 0 评论 0原文

我花了很长一段时间浏览 MySQL 博客和一些问题,试图弄清楚如何在我的 Mac OS 10.6.7 上安装 MySQL 服务器和 MySQLdb for Python。我想我通过 MacPorts 安装了 MySQL 服务器(这花了很长时间),但我无法导入 MySQLdb (从这里下载)使用Python。

这是我得到的错误:

import MySQLdb
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Library/Frameworks/EPD64.framework/Versions/6.3/lib/python2.6/site-packages/MySQL_python-1.2.3-py2.6-macosx-10.5-x86_64.egg/MySQLdb/__init__.py", line 19, in <module>
import _mysql
ImportError: dlopen(/Library/Frameworks/EPD64.framework/Versions/6.3/lib/python2.6/site-packages/MySQL_python-1.2.3-py2.6-macosx-10.5-x86_64.egg/_mysql.so, 2): Library not loaded: libmysqlclient.18.dylib
Referenced from: /Library/Frameworks/EPD64.framework/Versions/6.3/lib/python2.6/site-packages/MySQL_python-1.2.3-py2.6-macosx-10.5-x86_64.egg/_mysql.so
Reason: image not found

我按照 这个问题用于清理并重新安装我的 MySQLdb 安装。完成这些步骤一切正常,但它导致了同样的错误。

我也不确定为什么它调用 EPD64.framework 目录——模块文件夹和内容实际上包含在 /Library/Frameworks/Python.Framework/.../site-packages 中。 MacPorts 是否可能在某个地方跨接了电线?

(我做了一个额外的步骤,将 site.cfg 中的 msyql_config 路径修改为 /user/local/mysql/bin/mysql_config )

我还尝试遵循 这个问题但根本找不到 /User/$User/.python-eggs 目录,所以不知道该怎么办那。

有什么想法吗?

I've spent what feels like forever running down MySQL blogs and SO questions trying to figure out how to install a MySQL server and MySQLdb for Python on my Mac OS 10.6.7. I think I got the MySQL server installed through MacPorts(which took an eternity), but I can't import MySQLdb (downloaded from here) with Python.

Here's the error I get:

import MySQLdb
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Library/Frameworks/EPD64.framework/Versions/6.3/lib/python2.6/site-packages/MySQL_python-1.2.3-py2.6-macosx-10.5-x86_64.egg/MySQLdb/__init__.py", line 19, in <module>
import _mysql
ImportError: dlopen(/Library/Frameworks/EPD64.framework/Versions/6.3/lib/python2.6/site-packages/MySQL_python-1.2.3-py2.6-macosx-10.5-x86_64.egg/_mysql.so, 2): Library not loaded: libmysqlclient.18.dylib
Referenced from: /Library/Frameworks/EPD64.framework/Versions/6.3/lib/python2.6/site-packages/MySQL_python-1.2.3-py2.6-macosx-10.5-x86_64.egg/_mysql.so
Reason: image not found

I followed the instructions on this question for cleaning up and reinstalling my MySQLdb installation. Everything worked fine going through the steps, but it resulted in the same error.

I'm also not sure why it's calling the EPD64.framework directory -- the module folder and contents are actually contained in /Library/Frameworks/Python.Framework/.../site-packages. Could MacPorts have crossed the wires somewhere?

(I did one extra step of modifying the msyql_config path in site.cfg to /user/local/mysql/bin/mysql_config)

I also tried to follow the advice of this question but can't find the /User/$User/.python-eggs directory at all, so not sure what to do about that.

Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

半世蒼涼 2024-11-09 14:22:37

您问题中的第二个链接包含答案,但是其中包含了太多不必要的额外信息...

只需确保您有以下 bin:/usr/local/mysql/bin/mysql_config

时,您需要做的就是将 setup_posix.py 中的 mysql_config.path 更改为:

mysql_config.path = "/usr/local/mysql/bin/mysql_config"

尝试简单地这样做,不要执行他们建议的符号链接或清洗鸡蛋等。

The second link in your question kind of contains the answer, but there is so much extra information mucked in that's unnecessary...

Simply make sure you have the following bin: /usr/local/mysql/bin/mysql_config

And then when installing MySQLdb all you need to do is change mysql_config.path in setup_posix.py to:

mysql_config.path = "/usr/local/mysql/bin/mysql_config"

Try simply doing that, don't do the symlinks they suggest or clean the eggs etc.

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