[Baypiggies] Mac users using wxPython

Ned Deily nad at acm.org
Tue Jan 11 10:29:57 CET 2011


In article 
<AANLkTikzzufAbV9PpUvHnC5P6xYYiZjom_MtSQ_ba_py at mail.gmail.com>,
 Tony Cappellini <tony at tcapp.com> wrote:

> > In case I wasn't clear, I meant trying the wxpython.org wxpython2.7 with
> > the python2.7 installed by the 32-bit python2.7 installer from
> > python.org (rather than with the MacPorts-installed python2.7):
> 
> I installed python 27 via macports, but I don't know if it was 32 or 64-bit.

You can tell by using the file command:

$ file /opt/local/bin/python2.7
/opt/local/bin/python2.7: Mach-O universal binary with 2 architectures
/opt/local/bin/python2.7 (for architecture x86_64):   Mach-O 64-bit 
executable x86_64
/opt/local/bin/python2.7 (for architecture i386):  Mach-O executable i386

In this case, I have installed a "universal" Python2.7 capable of 
running in either 64-bit or 32-mode mode.  OS X 10.6 prefers to run a 
64-bit executable when possible over a 32-bit mode unless forced.

$ /opt/local/bin/python2.7 -c 'import sys;print(sys.maxsize)'
9223372036854775807
$ arch -x86_64 /opt/local/bin/python2.7 -c 'import 
sys;print(sys.maxsize)'
9223372036854775807
$ arch -i386 /opt/local/bin/python2.7 -c 'import sys;print(sys.maxsize)' 
2147483647

Of course, if there is only one architecture in the executable, it has 
to try to use that.  And that's what is happening with the MacPorts wx.  
Looking at the MacPorts portfile for py27-wxpython:

http://trac.macports.org/browser/trunk/dports/python/py27-wxpython/Portfi
le

it has an explicit "configure.build_arch i386" meaning wxpython will 
only be built as 32-bit.  (The reason for that is that apparently wx 
uses deprecated OS X Carbon APIs which are only available in 32-bit 
mode.)   So the traceback you got undoubtedly means that the MacPorts 
python2.7 is running in 64-bit mode and the import of the extension 
module in the wx package fails because it is 32-bit only: 

> >> import wx
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
>   File 
>   "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/s
>   ite-packages/wx-2.8-mac-unicode/wx/__init__.py",
> line 45, in <module>
>     from wx._core import *
>   File 
>   "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/s
>   ite-packages/wx-2.8-mac-unicode/wx/_core.py",
> line 4, in <module>
>     import _core_
> ImportError: 
> dlopen(/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2
> .7/site-packages/wx-2.8-mac-unicode/wx/_core_.so,
> 2): no suitable image found.  Did find:
> 	
> /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site
> -packages/wx-2.8-mac-unicode/wx/_core_.so:
> mach-o, but wrong architecture

One solution to that is to run the python2.7 as 32-bit.  If it was built 
as a 64-/32-bit universal, then the "arch -i386" trick above should work:

$ arch -i386 /opt/local/bin/python2.7 -c 'import wx'
$ # no errors

If not (i.e. it's only 64-bit), the arch command will fail.  In that 
case, you can force MacPorts to rebuild and reinstall all of the 
necessary ports as universal ones by this:

$ port upgrade --force --enforce-variants  \
   py27-wxpython python27 +universal

You may want to edit the MacPorts variants file to include +universal so 
all future port installs and upgrade are built as universal, if 
possible, and you won't need to add the +universal to each port command.  
The file is at:  /opt/local/etc/macports/variants.conf

In theory, it is possible to tell MacPorts you only want to build 32-bit 
executables, period, but that is a bit more complicated and probably 
more fragile.  I don't recommend it.

OR , as suggested previously,  you could go with the python.org 32-bit 
Python 2.7 with which the wxpython.org installer is compatible.  From 
the command line to illustrate (it's easier to run everything from your 
web browser and the Finder by clicking on things):

$ curl -O \
 http://www.python.org/ftp/python/2.7.1/python-2.7.1-macosx10.3.dmg
$ open python-2.7.1-macosx10.3.dmg 
$ open "/Volumes/Python 2.7.1/Python.mpkg"
$ # click buttons in python installer
$ umount "/Volumes/Python 2.7.1"
$ curl -O \ 
http://cdnetworks-us-2.dl.sourceforge.net/project/wxpython/wxPython/2.8.1
1.0/wxPython2.8-osx-unicode-2.8.11.0-universal-py2.7.dmg
$ open wxPython2.8-osx-unicode-2.8.11.0-universal-py2.7.dmg 
$ open /Volumes/wxPython2.8-osx-unicode-2.8.11.0-universal-py2.7/\
wxPython2.8-osx-unicode-universal-py2.7.pkg
$ # click buttons in wxpython installer
$ umount /Volumes/wxPython2.8-osx-unicode-2.8.11.0-universal-py2.7 
$ /usr/local/bin/python2.7 -c "import wx"
$ # no errors

-- 
 Ned Deily,
 nad at acm.org



More information about the Baypiggies mailing list