Skip to content

Using Python’s Core Graphics bindings in Snow Leopard

February 28, 2010

If you’ve recently upgraded to Snow Leopard, you may have noticed that you can’t import Core Graphics in Python. Each Mac is built off its Core Graphics framework, which includes the pair of Mac OS X technologies Quartz 2D and the Quartz Compositor. Following the transition from Leopard to Snow Leopard, Apple updated the Python binaries to be (by default) 64-bit. The CGBindings did not survive this transition (mistake? oversight?). When you try to import CoreGraphics into Python you may receive the following error:

ImportError:
/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/
CoreGraphics/_CoreGraphics.so: no appropriate 64-bit architecture
(see "man python" for running in 32-bit mode)

The bindings are still available to 32-bit Python, however. One workaround (as suggested by Jaharmi) is to specifically set your preferred python version to 32-bit:

$ export VERSIONER_PYTHON_PREFER_32_BIT=yes

This will set your Python to run in 32-bit mode. Is this what you want? Not necessarily… we are given the 64-bit binaries hence we want to use them for development. After all, Snow Leopard operates off a 64-bit hybrid kernel. This is simply a workaround.

While you can use CGBindings for 32-bit Python, you must use PyObjC to replace their functionality in the default 64-bit system. It seems Apple wants to completely switch over to this completely and in the meantime has offered a grace period for transition. Therefore making the switch is inevitable, albeit inconvenient.

Advertisement
No comments yet

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.