从 pypm 安装的 MySQLdb 不适用于 Mac OSX 上的 32 位 python

发布于 2024-11-05 14:48:39 字数 1614 浏览 1 评论 0原文

在继续之前,以下是我的 Mac 以及已安装的 python (ActivePython) 和 wxpython 版本的一些详细信息:

Mac 版本:10.6.6 Python版本:2.7.1(ActiveState Python) wxPython 版本:wxPython2.8-osx-unicode-py2.7

这是我编写来测试的一个小代码:

#! /usr/bin/env arch -i386 /usr/local/bin/python

import time
import random
import re
import wx
from wx.lib.mixins.listctrl import ListCtrlAutoWidthMixin
import serial
import itertools
import datetime
import sys
import os
import MySQLdb

print "Hello World"

这是我运行它时得到的错误:

Traceback (most recent call last):
  File "./sar.pyw", line 13, in <module>
    import MySQLdb
  File "/Users/ven/Library/Python/2.7/lib/python/site-packages/MySQLdb/__init__.py", line 19, in <module>
    import _mysql
ImportError: dlopen(/Users/ven/Library/Python/2.7/lib/python/site-packages/_mysql.so, 2): Symbol not found: _mysql_affected_rows
  Referenced from: /Users/ven/Library/Python/2.7/lib/python/site-packages/_mysql.so
  Expected in: flat namespace
 in /Users/ven/Library/Python/2.7/lib/python/site-packages/_mysql.so

正如你所看到的在shebang行中使用32位python,因为我需要使用 wxpython ,它仅在32 位。现在,唯一对 32 位 python 有问题的包是 MySQLdb ,已安装使用:

pypm install mysql-python

如果我刚刚删除该行

import MySQLdb
from the above piece of code, it runs perfectly and prints "Hello World".

如果我从 shebang 行中删除“arch -i386”,则 wxpython 包将不起作用。我想同时使用wxpython和MySQLdb。我该怎么做?

Before proceeding further, here are some details of my Mac and the installed python (ActivePython) and wxpython versions:

Mac version: 10.6.6
Python version: 2.7.1 (ActiveState Python)
wxPython version: wxPython2.8-osx-unicode-py2.7

Here is a small code that I wrote to test:

#! /usr/bin/env arch -i386 /usr/local/bin/python

import time
import random
import re
import wx
from wx.lib.mixins.listctrl import ListCtrlAutoWidthMixin
import serial
import itertools
import datetime
import sys
import os
import MySQLdb

print "Hello World"

Here is the error that I got from running it:

Traceback (most recent call last):
  File "./sar.pyw", line 13, in <module>
    import MySQLdb
  File "/Users/ven/Library/Python/2.7/lib/python/site-packages/MySQLdb/__init__.py", line 19, in <module>
    import _mysql
ImportError: dlopen(/Users/ven/Library/Python/2.7/lib/python/site-packages/_mysql.so, 2): Symbol not found: _mysql_affected_rows
  Referenced from: /Users/ven/Library/Python/2.7/lib/python/site-packages/_mysql.so
  Expected in: flat namespace
 in /Users/ven/Library/Python/2.7/lib/python/site-packages/_mysql.so

As you can see I am using 32-bit python in the shebang line because I need to work with wxpython which runs only on 32-bit. Now, the only package that has problem with the 32-bit python is the MySQLdb which has been installed using:

pypm install mysql-python

If I just removed the line

import MySQLdb

from the above piece of code, it runs perfectly and prints "Hello World".

If I removed "arch -i386" from the shebang line, the wxpython package doesn't work. I want to use both wxpython and MySQLdb at the same time. How do I do it?

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

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

发布评论

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

评论(1

铃予 2024-11-12 14:48:39

重复 ;-)

这是一个 已知错误 - mysql-python 包目前仅针对 64 位构建。

我想同时使用wxpython和MySQLdb。我该怎么做?

wxPython 2.8 不支持 64 位(由于使用 Carbon),这就是 PyPM 包仅针对 32 位构建的原因。你可以尝试使用wxPython 2.9。

解决方法:使用 pypm 删除 wxpython (pypm uninstall wxpython),然后安装开发 cocoa 二进制文件 wxPython2.9-osx-cocoa-py2.7 > 来自 wxpython.org

Duplicate ;-)

This is a known bug -- the mysql-python package is built only for 64-bit at the moment.

I want to use both wxpython and MySQLdb at the same time. How do I do it?

wxPython 2.8 doesn't support 64-bit (due to using Carbon), this is why the PyPM package is built for only 32-bit. You could try using wxPython 2.9.

Workaround: remove wxpython using pypm (pypm uninstall wxpython), and then install the development cocoa binary wxPython2.9-osx-cocoa-py2.7 from wxpython.org.

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