2

Hi I'm trying to use PIL to be able to upload images to my django website through the admin interface.

Heres the result of a test that I ran after I installed PIL:

cfarm:Imaging-1.1.7 christopherfarm$ python selftest.py 
--------------------------------------------------------------------
PIL 1.1.7 TEST SUMMARY 
--------------------------------------------------------------------
Python modules loaded from ./PIL
Binary modules loaded from /Library/Python/2.6/site-packages/PIL
--------------------------------------------------------------------
*** PIL CORE support not installed
*** TKINTER support not installed
*** JPEG support not installed
--- ZLIB (PNG/ZIP) support ok
*** FREETYPE2 support not installed
*** LITTLECMS support not installed
--------------------------------------------------------------------
Running selftest:
*****************************************************************
Failure in example:
try:
 _info(Image.open(os.path.join(ROOT, "Images/lena.jpg")))
except IOError, v:
 print v
from line #24 of selftest.testimage
Expected: ('JPEG', 'RGB', (128, 128))
Got: decoder jpeg not available
1 items had failures:
   1 of  57 in selftest.testimage
***Test Failed*** 1 failures.
*** 1 tests of 57 failed.

I'm a bit of a newbie when it comes to this, is there a way to get all the types supported? I also tried to upload a .png file and it still didn't work. I get the error: Upload a valid image. The file you uploaded was either not an image or a corrupted image.

Also when trying to run sudo python setup.py build I get the following error:

cfarm:Imaging-1.1.7 christopherfarm$ sudo python setup.py build
running build
running build_py
running build_ext
--- using frameworks at /System/Library/Frameworks
building '_imaging' extension
creating build/temp.macosx-10.6-universal-2.6
creating build/temp.macosx-10.6-universal-2.6/libImaging
gcc-4.2 -fno-strict-aliasing -fno-common -dynamic -DNDEBUG -g -fwrapv -Os -Wall -Wstrict-prototypes -DENABLE_DTRACE -arch i386 -arch ppc -arch x86_64 -pipe -DHAVE_LIBJPEG -DHAVE_LIBZ -I/System/Library/Frameworks/Tcl.framework/Headers -I/System/Library/Frameworks/Tk.framework/Headers -IlibImaging -I/opt/local/include -I/System/Library/Frameworks/Python.framework/Versions/2.6/include -I/usr/local/include -I/usr/include -I/System/Library/Frameworks/Python.framework/Versions/2.6/include/python2.6 -c _imaging.c -o build/temp.macosx-10.6-universal-2.6/_imaging.o
_imaging.c:3017: warning: initialization from incompatible pointer type
_imaging.c:3077: warning: initialization from incompatible pointer type
/usr/libexec/gcc/powerpc-apple-darwin10/4.2.1/as: assembler (/usr/bin/../libexec/gcc/darwin/ppc/as or /usr/bin/../local/libexec/gcc/darwin/ppc/as) for architecture ppc not installed
Installed assemblers are:
/usr/bin/../libexec/gcc/darwin/x86_64/as for architecture x86_64
/usr/bin/../libexec/gcc/darwin/i386/as for architecture i386
_imaging.c:3017: warning: initialization from incompatible pointer type
_imaging.c:3077: warning: initialization from incompatible pointer type
l_imaging.c:3281: fatal error: error writing to -: Broken pipe
compilation terminated.
_imaging.c:3017: warning: initialization from incompatible pointer type
_imaging.c:3077: warning: initialization from incompatible pointer type
^R
lipo: can't open input file: /var/tmp//ccuPSrVi.out (No such file or directory)
error: command 'gcc-4.2' failed with exit status 1

Seems like something is wrong with the pointer?

locoboy
  • 38,002
  • 70
  • 184
  • 260

3 Answers3

6

You have to install support for JPEG, for example in mac if you are using homebrew just:

brew install jpeg

or for ubuntu

sudo apt-get install libjpeg62-dev

You will probably need to link the installed library so when PIL compiles it will know where to look for the JPEG support. This will be the same for the other non supported libraries.

There is another option named pillow, you can take a look here: http://pypi.python.org/pypi/Pillow

It just handles some things easier than PIL. Also check this

Community
  • 1
  • 1
Hassek
  • 8,715
  • 6
  • 47
  • 59
  • i installed using brew but still doesn't work. when I try to `python setup.py build` i also get the following error above – locoboy Jan 28 '12 at 19:25
  • In the BUILDME file it says to use "python setup.py build_ext -i" that worked for me. Please let me know if this works for you – Hassek Jan 29 '12 at 07:14
  • i had to ln -s my pil from brew to the python/2.6/site-packages, after that it worked – locoboy Jan 29 '12 at 21:33
0

If brew doesn't work for libjpeg, there's a nice libjpeg package you can download. I wrote about it here:

http://markliu.me/2011/aug/20/installing-libjpeg-and-pil-on-osx-snow-leopard-wit/

Spike
  • 5,040
  • 5
  • 32
  • 47
-1

Probably you need to edit setup.py file in your source package and add appropriate paths to where jpeg library is installed before building and installing PIL. Installation instructions provided in PIL source may be helpful.

machaku
  • 1,176
  • 8
  • 7
  • where would I find the path that it's jpeg is installed? – locoboy Jan 28 '12 at 23:18
  • I am not sure. May be at '/usr/local' or '/usr/local/lib' or you can read [this post](http://www.brantsteen.com/blog/python-27-libjpeg-pil-on-osx/) – machaku Jan 28 '12 at 23:55
  • yeah i tried to change it, still getting the same error though :( – locoboy Jan 29 '12 at 01:48
  • if you installed jpeg with homebrew it should be at "/usr/local/Cellar/jpeg", to know more about it just type "brew info jpeg" – Hassek Jan 29 '12 at 07:16