Archive for November, 2007

Fixing – PIL IOError: decoder jpeg not available

Thursday, November 8th, 2007

So you get PIL (the Python Imaging Library) all installed on your new system and you’re feeling proud of yourself. But then you go to do some tasks involving JPEG’s and you get this horriffic error:

IOError: decoder jpeg not available

Here’s how I re-installed PIL correctly. But before you try to reinstall it, make sure you’ve removed every ounce of PIL from your system. Somehow the reinstall didn’t work until I removed both the PIL site-packages install AND the temporary installation folder i.e., where the tar file unpacked to.

My sucessful re-installation of PIL on Ubuntu 7.04:

First remove your last install!
$ sudo rm -rf /usr/lib/python2.5/site-packages/PIL
$ sudo rm /usr/lib/python2.5/site-packages/PIL.pth
$ sudo rm ~/Imaging-1.1.6

Make sure you install at the libraries for both JPEG support and FreeType2:
$ sudo aptitude install libjpeg libjpeg-dev
$ sudo aptitude install libfreetype6 libfreetype6-dev

Get PIL again and do the install:
$ wget http://effbot.org/media/downloads/Imaging-1.1.6.tar.gz
$ gunzip Imaging-1.1.6.tar.gz
$ tar xvf Imaging-1.1.6.tar
$ cd Imaging-1.1.6/
$ python setup.py build_ext -i

Run the included test to make sure everything now works:
$ python selftest.py

If everything worked do the real install:
$ sudo python setup.py install

If my instructions still don’t help you, in your downloaded PIL archive you can also take a look at the included README file and read the comments in the included setup.py file for more setup instructions.

Python – How to Sort Alphabetically

Tuesday, November 6th, 2007

Here’s a code snippet showing how to sort alphabetically in your Python code:

>>> items=['greg','Car','car','Goose']
>>> items.sort(lambda x, y: cmp(x.lower(),y.lower()))
>>> items
['Car', 'car', 'Goose', 'greg']

Doing this will sort by the characters’ numerical byte values which normally isn’t what you would want:

>>> items.sort()
>>> items
['Car', 'Goose', 'car', 'greg']

Python – SyntaxWarning: name ‘x’ is used prior to global declaration

Monday, November 5th, 2007

I got an odd warning in Python today:
SyntaxWarning: name 'x' is used prior to global declaration

I think the answer is to put the global declaration for a variable before any uses of of that variable in a code block.

Here’s an example:

X=1 #our global
#Bad
def f():
    a=X
    global X
#Good
def f():
    global X
    a=X

Does anyone know why it’s just a warning?

Here are some helpful answers about using global variables in Python:
The rules for local and global variables in Python
I can’t use a global variable in a function? Help!

Mini Searches with Answers

Sunday, November 4th, 2007

These are links associated with recent searches I’ve done. They’re not difficult enough to warrant to their own posts but still super useful.

Very Thorough GoldMine SQL Table Definitions
It even has fields5 which I couldn’t find anywhere else.

UbuntuBootupHowto – Community Ubuntu Documentation
How to make your own script or daemon play nicely with the init.d stuff in Ubuntu.

www dot james mckay dot net ‽ Comment Timeout
This helps with WordPress spam by closeing down commenting on old posts. I tried it out but removed it because I thought it was blocking all comments but really my test comments were just getting picked up by the spam filter. I’ll have to try it again.

Happy Camel, match your GPS with your digital photographs
Give it a tracklog from a GPS device and some images and it will embed the correct coordinates in the right images, and even show you the pictures on Google Earth. Would anyone like me to make this into a utility at Utility Mill?

GRE – Additional Score Reports
How to find out your GRE scores. Ugg, I just want to know the score, why do I have to order a whole sealed report for $15.00!

SAT Sending Old Scores
How to get your old SAT scores. $20.00 this time!

Tags: , , , , , , , , , , , , , , , , , ,