Forums

Where PIL is kept?

Hello. I use PIL in my project. I puted pil.pth in my virtualenv and all worked good. But now i have got an error when i used python2.7 manage.py syncdb command... I tried to find PIL int /usr/lib/python2.7 but there are not python2.7 and python3.2 folders... I tried to find it in /usr/lib/python2.6 but there is not PIL

Hi there, you can find the location of any package by importing it and inspecting its __file__ attribute:

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

Thx. It works correctly. I used an old directory /usr/local/lib/python2.6/dist-packages/PIL-1.1.7-py2.6-linux-x86_64.egg/PIL . I took it from https://www.pythonanywhere.com/forums/topic/217/

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)

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.