导入 MySQLdb 时出错

发布于 2024-12-25 17:44:06 字数 738 浏览 1 评论 0原文

我已经尝试了一段时间让 MySQLdb 工作。我目前收到此错误:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "build/bdist.macosx-10.7-intel/egg/MySQLdb/__init__.py", line 19, in <module>
  File "build/bdist.macosx-10.7-intel/egg/_mysql.py", line 7, in <module>
  File "build/bdist.macosx-10.7-intel/egg/_mysql.py", line 6, in __bootstrap__
ImportError: dlopen(/Users/username/.python-eggs/MySQL_python-1.2.3-py2.7-macosx-10.7-intel.egg-tmp/_mysql.so, 2): Library not loaded: /usr/local/lib/libmysqlclient.18.dylib
  Referenced from: /Users/username/.python-eggs/MySQL_python-1.2.3-py2.7-macosx-10.7-intel.egg-tmp/_mysql.so
  Reason: image not found

有人知道我需要做什么才能纠正这些错误吗?

I have been trying for awhile now to get MySQLdb working. I am currently getting this error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "build/bdist.macosx-10.7-intel/egg/MySQLdb/__init__.py", line 19, in <module>
  File "build/bdist.macosx-10.7-intel/egg/_mysql.py", line 7, in <module>
  File "build/bdist.macosx-10.7-intel/egg/_mysql.py", line 6, in __bootstrap__
ImportError: dlopen(/Users/username/.python-eggs/MySQL_python-1.2.3-py2.7-macosx-10.7-intel.egg-tmp/_mysql.so, 2): Library not loaded: /usr/local/lib/libmysqlclient.18.dylib
  Referenced from: /Users/username/.python-eggs/MySQL_python-1.2.3-py2.7-macosx-10.7-intel.egg-tmp/_mysql.so
  Reason: image not found

Anyone know what I need to do in order to correct these errors?

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

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

发布评论

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

评论(1

淡忘如思 2025-01-01 17:44:06

看起来 MySQLdb 已针对错误的架构进行了自身编译。我正在运行 OSX Lion x86_64,我必须这样做:

$ file $(which python) # so I can check my python is 64 bit

和 64 位 MySQL

$ file $(which mysqld) # so I can check my MySQL is 64 bit too

您可以验证当前 MySQLdb 的体系结构是 32 位:

$ file /Users/username/.python-eggs/MySQL_python-1.2.3-py2.7-macosx-10.7-intel.egg-tmp/_mysql.so

然后我可以让 MySQLdb 工作的唯一方法是下载源代码,并使用

$ ARCHFLAGS='-arch x86_64' python setup.py install

它 进行编译强制 setup.py 构建 64 位库 (_mysql.so) 而不是 32 位。 (帽子提示 - 我发现这个所以问题很有帮助

,丹。

It looks like MySQLdb has compiled itself for the wrong architecture. I'm running OSX Lion x86_64 and I had to do this:

$ file $(which python) # so I can check my python is 64 bit

and 64bit MySQL

$ file $(which mysqld) # so I can check my MySQL is 64 bit too

You can verify the architecture of your current MySQLdb is 32bit:

$ file /Users/username/.python-eggs/MySQL_python-1.2.3-py2.7-macosx-10.7-intel.egg-tmp/_mysql.so

And then the only way I could get MySQLdb to work was to download the source, and compile with

$ ARCHFLAGS='-arch x86_64' python setup.py install

which forces the setup.py to build a 64 bit library (_mysql.so) rather than 32 bit. (Hat-tip - I found this so question to be helpful.

HTH, Dan

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