2

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.

4
  • Mac OSX comes with wxpython, but you have to use the 32-bit Python binary to use it. Commented May 7, 2011 at 20:02
  • Do I have to specify that on the python file, or do I have to install pyhton again? Commented May 7, 2011 at 23:37
  • @Jailborc there's an option you can set. I've made an answer. Commented May 8, 2011 at 0:29
  • Went to "wxpython.org/download.php" and choose "wxPython2.8-osx-unicode-py2.6". Mounted the disk image and ran the installer. Commented May 8, 2011 at 14:12

3 Answers 3

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.

Sign up to request clarification or add additional context in comments.

3 Comments

Note that the solution above is fine but only works with the Apple-supplied system Python 2.6 on 10.6. AFAIK, no other distributor of Python has implemented defaults support. Instead, you might see python-32 and/or python-64 symlinks. The situation is different with the standard python2.7 and python3.2; there you can use arch -i386 pythonx.x command. For various reasons, that often doesn't work with Python 2.6 on OS X 10.6.
But that would change python to allways run on 32-bit, am I right? Is there a way to make it run 32-bit when I want, but 64-bit otherwise?
@Jailborc use the defaults command before you run it. You could do something like alias python32='defaults write com.apple.versioner.python Prefer-32-Bit -bool yes; python and do the opposite for 64-bit python.
1

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.

Comments

0

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.