Installing PIL inside virtualenv for Ubuntu 9.10

2010-03-31 3 min read Django Python Eddie

I just removed a (real live) bat from my living room. That was easier than installing PIL in a virtualenv for Ubuntu 9.10. Why? Googling the subject seems to bring up a lot of old or mis-information. This will explain how… mostly so I can do it again next time.

I started with a –no-site-packages virtualenv, so as not to use (or more importantly depend) on any of the global site-packages. Ok, cool.

$ virtualenv --no-site-packages myEnv

First, I needed to install the python developer tools. (Use apt-get or aptitude, whatever floats your boat)

$ sudo aptitude install python-dev

Then, I needed to install libjpeg and libjpeg-dev. I’m not sure why, but I needed libjpeg simply doesn’t exist, so I needed to install libjpeg62. I can’t pretend that I know the difference (or if there is one). In fact, I may have gotten away with installing libjpeg62 and libjpeg-dev (rather than both “62” versions… libjpeg62 and libjpeg62-dev), but only further testing will tell.

Why? If you install PIL without this library, you’ll get those wonderful “decoder jpeg not available” messages in Python. Or worse yet, if you’re trying to use it in a Django, you may get some errors (specifically the “Upload a valid image. The file you uploaded was either not an image or a corrupted image” warning), or you may not get any until you open the shell. Either way, you can test with the method listed below. If you get the “decoder jpeg not available” message, your install didn’t work.

The zlib package handles PNGs.

$ sudo aptitude install libjpeg62 libjpeg62-dev $ sudo aptitude install zlib1g-dev $ sudo aptitude install libfreetype6 libfreetype6-dev

Alright, now we seem to be done with the prerequisites. Start your virtualenv (of course, myEnv in the example is the name of your virtualenv).

$ source myEnv/bin/activate

Download PIL and install. This will make sure to install PIL within your virtualenv’s site-packages.

(myEnv)$ wget http://effbot.org/downloads/Imaging-1.1.7.tar.gz (myEnv)$ tar zxvf Imaging-1.1.7.tar.gz (myEnv)$ cd Imaging-1.1.7 (myEnv)$ python setup.py install

If you run into further problems (the “decoder jpeg not available” message again), you may have to resort to the long directions to get PIL and libjpeg to play happily together, but I hope not.

Now that you have everything installed, test it. Open up a python shell from within your virtualenv.

(myEnv)$ python

Now try the following (with an image in your home directory) to see if everything is running smoothly.

Continue reading

Review of "Learning Website Development with Django"

2008-07-07 4 min read Books Django Programming Python Web Eddie

Cover, Learning Website Development with Django
Cover, Learning Website Development with Django
Over the past few weeks, I’ve been playing around with Django. Because of that, I’ve been looking at a few different books on the subject. I first started out with the Django Book, which took me a few days to read. I can’t say I absorbed it all, but I got the general idea. Then I decided to look into other books and found Learning Website Development with Django, by Ayman Hourieh. I started right away.

The book’s subtitle, “A beginner’s tutorial to building web applications, quickly and cleanly, with the Django application framework,” frames the book perfectly. Its target audience is programmers (moderately) familiar with Python, but who are, at the same time, new to Django. The book is really focused towards this audience. The other key word in the subtitle is “quickly.” This book moves along in a hurry while creating the demonstration app. I was quite comfortable (and pleased) by the pace, however, I can imagine that a more novice programmer may have a harder time dealing with the information flying by.

The book centers on building one app, a social bookmarking website similar to del.icio.us, or ma.gnolia. I think type of site was a good choice, since it provides the author with a varying degree of complexity to play around with. It allowed Mr. Hourieh to start with the basics. This book succeeds in starting simple and getting harder as it goes along. I also thought it was good to focus on creating just one website, rather than a bunch of mini-projects or examples, since it models a more real-life situation. The idea of a social bookmarking website, as well, is very useful because its features are currently en vogue, and can be found on many current sites.

Chapters One and Two are the obligatory “what is Django” and “how to install” chapters. The meat of the book starts in Chapter Three when the project is introduced. By the end of this third chapter, we’ve already quickly written three database models (Links, Users, and Bookmarks) and the main page. Chapter Four introduces Django’s built-in user authentication system (django.contrib.auth), and describes how to write login, logout, and registration pages. Chapter Five instructs us to write an additional database model (tags), which is more complex than the models we wrote previously. Here we also write pages to display the list of bookmarks, bookmarks by tags, and a tag cloud. [To illustrate how fast we’re moving, Chapter Five ends on page 91]

Continue reading

July 4

2008-07-04 2 min read Boston Django Python Red Sox Eddie

Photo by Vidiot. Click image for details.
Photo by Vidiot. Click image for details.
Happy July 4th! Now, with that out of the way…

My sister Tania was at the Nathan’s Hot Dog eating competition today. She was happy with the result, I was rooting for Kobayashi. Oh well. My roommate was rather disgusted by the whole thing. Me? I found myself REALLY wanting a hot dog.

Speaking of food… my roommate and I were flipping channels the other day and she insisted on stopping on the food network. They had a show on about local resturants known only to locals. The first part was on a place I’ve passed countless numbers of times, called Chaps Charcoal Resturant. It looked pretty good, and the prices are good, so I may have to visit soon.

Since I’m on a food kick at the moment, one more… this may also soon become my favorite thing. Gotta try it.

Elsewhere…

The Sox won, beating the Yankees today, but are still behind the Rays. If the Rays suffer injuries down the stretch, they’ll fall. However, that seems to be a big if. The Red Sox need to get a number of people back.

And more locally…

When I have some free moments, I’ve been working rebuilding gbyo.com in Django. The programming part isn’t particularly hard (despite not being familiar with Python… though, it’s not unlike other languages), and I kinda like the database API (It’s been a while, so I only barely remember ActiveRecord, but I seem to like this more). The thing I haven’t grasped yet is overall project structure. I’m working on that.

I’ve bought a number of books recently, and hope to start reading them soon. Right now, I am reading this, as the publishers were nice enough to send me a review copy. Review coming soon. Additionally, I want to post some more formal thoughts about Crockford’s Javascript book soon. (Note: yes, that first linked book cost me .48 cents, w/o shipping)

I’m trying to convince people to go on vacation with me. So far, I haven’t heard back from anyone. That will only stall me, it will not deter me.