Django ImageField validation error caused by incorrect PIL installation on MAC


Django ImageField validation error caused by incorrect PIL installation on MAC

I kept getting a validation error in the django admin pages while trying to upload an image. The validation error said:

Upload a valid image. The file you uploaded was either not an image or
a corrupted.

I really broke my brains on this one but finally got it to work! I knew for sure that the image was not corrupted so it had to be something else. After some googling I found a couple of pages on the Python Imagina Library and how it was kinda difficult to get that installed properly on MacOS. When I first installed Django I just used the standard “python install” command for installing PIL, but that did not install it correctly.

What worked for me was the following:

  1. Install the Apple XCodeTools (Either from the MacOS X install CD or register and download them here)
  2. Install the libjpeg for JPEG support by downloading the source here. Extract the downloaded file and move into the directory (most likely called “jpeg-6b”). Then type:
    cp /usr/share/libtool/config.sub .
    cp /usr/share/libtool/config.guess .
    ./configure –enable-shared
    sudo mkdir -p /usr/local/include
    sudo mkdir -p /usr/local/bin
    sudo mkdir -p /usr/local/lib
    sudo mkdir -p /usr/local/man/man1
    sudo make install
  3. Now for correctly installing PIL: Download it here. Unpack it and change the file:
    JPEG_ROOT = none
    ZLIB_ROOT = none

    JPEG_ROOT = “/usr/local/include”
    ZLIB_ROOT = “/usr/local/include”

    then run
    python build_ext -i
    sudo python install

That should be it! Hope that helps anyone!


7 comments for “Django ImageField validation error caused by incorrect PIL installation on MAC”

  1. Thank you so much for this detailed post. After much head banging, I couldn’t figure out why uploading jpegs wasn’t working. This worked perfectly.

    Posted by Rob | October 16, 2008, 8:12 pm
  2. Good to hear it was helpful!

    Posted by Joost | October 16, 2008, 8:27 pm
  3. Thanks ! :)

    Posted by Japey | January 11, 2009, 7:43 pm
  4. Thank you so much, was really helpful and works like a charm!

    Posted by Olivier | February 15, 2009, 9:49 pm
  5. THANKS! Couldn’t be more concise. Worked first time!

    Posted by Evan | May 26, 2009, 5:29 am
  6. Thank you!! This type of thing can take hours and hours to diagnose and repair — and your recipe “just works”…!

    Posted by Peter | July 6, 2009, 10:27 pm
  7. Thanks!

    Posted by Jerry | April 11, 2010, 11:55 pm

Post a comment


  • No categories

Django Hosting:

DjangoDays recommends the following Django hosting provider: