Error Importing wxPython

你离开我真会死。 提交于 2019-12-24 00:02:49

问题


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.


回答1:


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.




回答2:


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.




回答3:


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.



来源:https://stackoverflow.com/questions/5923651/error-importing-wxpython

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!