Forums

python imaging library

hello guys, i'm having trouble to setup my app which have a models.ImageField(), when i try to sync database, i got an error, it says i need to install Python Imaging Library, is there anyway to install this? because i'm using django 1.4, i setup the app on virtualenv, and i try pip install PIL, no good, it says 'not a valid package name'

PIL doesn't install nicely via pip and it requires compilation so it can't be user-installed on PythonAnywhere, either.

Your best bet is to use the system PIL from within the virtualenv. Just drop a file called pil.pth into lib\python2.6\site-packages in your virtual env. It should contain the full path to the already-installed PIL: /usr/local/lib/python2.6/dist-packages/PIL-1.1.7-py2.6-linux-x86_64.egg/PIL

You can use the same trick for other libraries if you just want to use the system-wide library without installing it into your virtualenv.

This thread does not fully explain how to fix the problem. I just wrote this for my project wiki page, hopefully a sysop can grab it for the howto page.

Getting access to a system package/library

If your bash term defaults to load your environment exit it with deactivate

Run python, and import the library you want, for example

import PIL
PIL.__file__ 
'/usr/local/lib/python2.7/site-packages/PIL/PIL/__init__.pyc'

Copy the path (/usr/local/lib/python2.7/site-packages/PIL/)

Navigate to the virtual env's site-packages folder, for example ~/.virtualenvs/django15/lib/python2.7/site-packages

Use a file editor to create a file named after the desired import with a .pth extension like pil.pth

nano pil.pth

Put (copy) in the path detected earlier

Save the file.

Restart your virtual environment, for example workon django15

Start Python, and re-try the import such as:

$ workon django15

$ python

Python 2.7.3 (default, Mar 5 2013, 16:37:26)

[GCC 4.4.5] on linux2

Type "help", "copyright", "credits" or "license" for more information.

import PIL

PIL.__file__

'/usr/local/lib/python2.7/site-packages/PIL/PIL/__init__.pyc'

EDIT by admin - helped out with the formatting - it looks like markdown and codehilite don't like code blocks in lists (tried both ordered and unordered)

I'm having trouble fixing the layout in my post... I copied it from my TRAC wiki page, I thought I adjusted it to display reasonably well but.... nope.

Note: That python paths point not to the modules themselves, but to their parent directories!

on this page:

http://djangotricks.blogspot.ca/2008/09/note-on-python-paths.html

I just changed my south.pth file to end it at the site-packages folder.

That does work, but be careful because that will essentially include all the system packages in your virtualenv.