Recently I found out that in Django uses PIL to handle image uploads.
I managed to get a Bluehost account to run Django (it works! and I'll
be putting a *real* tutorial RealSoonNow), but I can't find my way
around installing PIL. Installation finishes with gcc belching a lot
of warnings and dying miserably. Bluehostś support guys haven't been
helpful yet, so... I turn to you.
Is there a way around PIL? Can Django use another kind of library? If
not, has anyone got around this? Maybe by getting a precompiled Linux
PIL?
Thanks a lot!
--
Carlos Yoder
http://carlitosyoder.blogspot.com
> http://packages.debian.org/unstable/python/python-imaging
> ?
Don't think so. I don't have root access to my box in Bluehost. Can
anythone think of an alternative, short of telling support to install
it themselves?
Regards,
> Don't think so. I don't have root access to my box in Bluehost. Can
> anythone think of an alternative, short of telling support to install
> it themselves?
tell them - PIL is such an integral part of all python programs that
python hosting is of now use without it. They should be ashamed of
themselves ;-)
--
regards
kg
http://lawgon.livejournal.com
http://avsap.org.in
Technically all PIL is needed for is determining height, width and what
not of the image. If you do not need it or can ask the user, then PIL is
nice but not required. May take a little hacking, but it should be
feasible to ignore the warning.
Another option is to see if imagemagick / graphicsmagick is installed
and write a wrapper which uses that instead of PIL. Also feasible and
should be relatively easy.
Maybe so, but unfortunately I'm just too much of a Python newbie to
try tackling that, while the clock is ticking for the Django app I
must get thru the door.
It's getting frustrating, all of this obstacles (which I believe are
not Django's fault, but related to sysadmins' ignorance). We *really*
need to think of a "providing Django support" tutorial for sysadmins,
as we discussed briefly in the last few days... otherwise a lot of
people would be scared away from Django because it's "too hard" or
"unsupported".
Anyway, I'll keep you posted, thanks a lot to you all!
If you need to get started quickly, you can use FileField instead of
ImageField, so the PIL won't be necessary. The requirements of the
uploaded image may be written in help_text. Maybe some validation of
the image width and height can be done using Javascript. I'm not sure
about that, you should check, whether it is posible to retrieve the
dimensions of the selected file through Javascript, writing something
like that:
oImg = new Image();
oImg.onload = function() {
alert(oImg.width + "x" + oImg.height);
}
oImg.src = document.getElementById("fileUploadFieldId").value;
(The script is written on the fly, I am not sure whether it works correctly)
Good luck!
Aidas Bendoraitis [aka Archatas]
I'll get cracking.
Best regards,
> > Don't think so. I don't have root access to my box in Bluehost. Can
> > anythone think of an alternative, short of telling support to install
> > it themselves?
>
> Technically all PIL is needed for is determining height, width and what
> not of the image. If you do not need it or can ask the user, then PIL is
> nice but not required. May take a little hacking, but it should be
> feasible to ignore the warning.
if that's all you need, you don't really have to compile PIL.
just copy the contents of the "PIL" directory to some suitable location
on your path, and you get a PIL install that can identify and open most
image formats (you'll get errors if you're actually trying to do
something with the pixels, though).
example:
>>> from PIL import Image
>>> im = Image.open("Images/lena.jpg")
>>> im.mode
'RGB'
>>> im.size
(128, 128)
>>> im.load()
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "PIL/ImageFile.py", line 217, in load
return Image.Image.load(self)
File "PIL/Image.py", line 607, in load
return self.im.pixel_access(self.readonly)
AttributeError: pixel_access
</F>
I may be wrong here, but I think deb packages can be installed
anywhere. The important thing is that Python be able to find and use
it.
I think you can download the .deb, then do something like this:
dpkg -i -instdir=/some/path/under/your/home your.deb
from the man page:
--root=dir | --admindir=dir | --instdir=dir
Change default directories. admindir defaults to /var/lib/dpkg and
contains many files that give information about status of installed or
uninstalled packages, etc. instdir defaults to / and refers to the
directory where packages are to be installed. instdir is also the
directory passed to chroot(2) before running package's installation
scripts, which means that the scripts see instdir as a root directory.
Changing root changes instdir to dir and admindir to dir/var/lib/dpkg.
Since you'll be installing to a non-standard location of PIL, you'll
need to make sure it's on the path (and on Python's path, which I
think you can do with SetEnv in your apache conf), and then (I think)
you should be set.