vendredi 25 janvier 2008

Executing Python scripts importing the CoreGraphics module

If you get the following error

Traceback (most recent call last):
File "spiraler.py", line 5, in ?
from CoreGraphics import *
ImportError: No module named CoreGraphics

when trying to execute a Python script which imports the CoreGraphics module, e.g. via

from CoreGraphics import *

the problem lies with the fact that the referred CoreGraphics module is only available in the Python distribution that comes installed with OS X in /System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/plat-mac/Carbon/CoreGraphics.py and doesn't come with standard distributions from www.python.org which install symlinks in /usr/local/bin and modify the PATH environment variable to put /usr/local/bin in front.

A way to address the issue consists, at least for scripts that would be executed directly from the terminal (through chmod u+x), in adding the following line to the first line of the script:

#!/usr/bin/python


Initially took me some time to figure out what was the problem so i hope this will allow anybody reading this to save some time by not having to search for a solution.

Errors in Apple "Image Unit Tutorial"

While following the Image Unit Tutorial (the 2007-10-31) version, i found a few errors that prevented the correct building of the sample Image Units.

In summary, the errors affect the Detective Lens Image Unit and the Pixellate Filter.

For the Detective Lens Filter ImageUnit example, the following changes are required in the Detective Lens Objective-C section:
  1. To be in line with DetectiveLensFilter.h of step 5, DetectiveLensFilter.m shall be corrected by changing inputWidth in customAttributes (step 10) into inputLensDiameter
  2. Accordingly, method outputImage shall be modified (step 13) so that all occurences of inputWidth are changed into inputLensDiameter
  3. Also in step 13, in outputImage, CIFilter *f; shall read CIFilter *compositedImage;
  4. In DetectiveLensFilter.m, the init method shall be modified so that path and url variables are declared as follows:
NSString *path = nil;
NSURL *url = nil;

For the Pixellate filter:
  1. In Pixellate.m, in method outputImage (step 8), PixellateTwoFilterKernel shall be changed to PixellateFilterKernel
Put online in the hope that it may help somebody.