导入 wxPython 时出错

发布于 2024-11-05 20:19:09 字数 603 浏览 2 评论 0原文

我刚刚安装了 wxPython,没有任何问题。我在 Snow Leopard Mac 上使用 Python 2.6 并下载了相应的 wxPython 版本。

我首先输入一个非常基本的 wxPython 应用程序,但出现以下错误:

ImportError: No module named wx 

代码如下:

import wx

class Application(wx.Frame):

  def __init__(self, parent, id):
      wx.Frame.__init__(self, parent, id, 'Hello World', size = (300, 200))


if __name__=='__main__':
  app = wx.PySimpelApp()
  frame = Application(parent = None, id = 1)
  frame.Show()
  app.MainLoop()

我使用的 Python 版本是否错误,是否是 32/64 位情况错误?如果是这样,我该如何解决?

编辑:强制 python 以 32 位运行,问题仍然存在。

I've just installed wxPython with no problems. I'm on a Snow Leopard Mac using Python 2.6 and downloaded the corresponding wxPython version.

I've started by typing a very basic wxPython app, but I'm getting the following error:

ImportError: No module named wx 

The code is the following:

import wx

class Application(wx.Frame):

  def __init__(self, parent, id):
      wx.Frame.__init__(self, parent, id, 'Hello World', size = (300, 200))


if __name__=='__main__':
  app = wx.PySimpelApp()
  frame = Application(parent = None, id = 1)
  frame.Show()
  app.MainLoop()

Am I using a wrong version of Python, is it a 32/64-bit situation bug? If so, how do I solve it?

EDIT: Forced python to run at 32-bit, the issue sustains.

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

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

发布评论

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

评论(3

赠意 2024-11-12 20:19:09

您不能在 64 位模式下使用 wxPython。首先,强制Python使用32位二进制文​​件:

defaults write com.apple.versioner.python Prefer-32-Bit -bool yes

然后你可以使用内置的Python和内置的wxPython。

You can't use wxPython in 64-bit mode. First, force Python to use the 32-bit binary:

defaults write com.apple.versioner.python Prefer-32-Bit -bool yes

Then you can use the builtin Python and the builtin wxPython.

中二柚 2024-11-12 20:19:09

好吧,问题是我正在运行 python 2.5。

对于所有在安装 wxPython 或任何其他 python 模块时遇到困难的 MacOSX 用户:请确保您的 Python 版本与模块请求的版本相同。 MacOS 中包含的 python 版本往往比上一个稳定版本更旧。

感谢所有帮助过我的人。

Ok, the problem was I was running python 2.5.

To all MacOSX users who get stuck trying to install wxPython or any other python module: make sure your Python version is the same as the requested by the module. The python version included in MacOS tends to be older than the last stable one.

Thank you to all who helped me out.

对你而言 2024-11-12 20:19:09

我很确定你不应该使用 wxPython 的标准 MacPython 安装,但我没有 Mac,所以我不确定......仅供参考:wxPython 的 cocoa 版本确实支持 64 位模式, 尽管。

I'm pretty sure you're not supposed to use the standard MacPython install with wxPython, but I don't have a Mac, so I'm not sure...FYI: The cocoa build of wxPython DOES support 64-bit mode, though.

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