Search This Blog

Monday, November 28, 2011

No module named PIL - after buildout

If you are using buildout to install PIL and if you get this error, check once in the eggs directory. If there is a PIL egg directory, check its contents. If there are files directly, that is the reason for the error. You can manually move all those contents to PIL subdirectory or add the following buildout part to your buildout script

# ============================================================================================== #
# PIL Hack #
# When buildout install PIL egg, it keeps all files under the PIL-1.1.7-py2.6-X-X-universal.egg. #
# We need to put all the files under a subdirectory PIL inside this folder to make it work. #
# ============================================================================================== #
[PIL-hack]
recipe=iw.recipe.cmd:py
on_install=true
on_update=true
cmds=
>>> import os
>>> while True:
>>> lst = []
>>> for p in os.listdir('${buildout:eggs-directory}'):
>>> if p.startswith('PIL-${versions:PIL}') and p.endswith('.egg'):
>>> lst.append(p)
>>> if len(lst) > 1:
>>> print '\033[91m' + 'I am confused. Multiple PIL eggs found. %s.' % lst + '\033[0m'
>>> raw_input('Delete the one which is not required and then press Enter to continue...')
>>> elif len(lst) == 0:
>>> print '\033[91m' + 'No PIL egg found in eggs directory' + '\033[0m'
>>> raw_input('Press Enter to continue...')
>>> break
>>> elif len(lst) == 1:
>>> path = os.path.join('${buildout:eggs-directory}', lst[0])
>>> path2 = os.path.join(path, 'PIL')
>>> if not os.path.exists(path2):
>>> print '\033[92m' + ('Using PIL egg: %s' % lst[0]) + '\033[0m'
>>> lstdir = os.listdir(path)
>>> os.mkdir(path2)
>>> for p in lstdir:
>>> os.rename(os.path.join(path, p), os.path.join(path2, p))
>>> break

Python colors on command line print

While writing a command line script, adding colors might ease understanding the output. To print a line in color just follow this simple technique
print '\033[91m' + 'my error string' + '\033[0m'
You might have guessed it by now. '\033[' is a control char and '0m'/ '91m' define the color to be displayed.
Few examples: 0m is white 91m red 92m green 93m orange 94m blue Hope this helps