Django says all images are invalid, but PIL works

I am launching a new Linode on Ubuntu 12.04 with Nginx, Gunicorn and Django 1.4. Uploading to an image field (which works locally) claims that the file is damaged or invalid, including for images that work locally.

PIL works. I can load, check and collect various image properties.

I also use virtualenv.

Any suggestions?

Additional Information:

-------------------------------------------------------------------- PIL 1.1.7 SETUP SUMMARY -------------------------------------------------------------------- version 1.1.7 platform linux2 2.7.3 (default, Apr 20 2012, 22:44:07) [GCC 4.6.3] -------------------------------------------------------------------- *** TKINTER support not available *** JPEG support not available *** ZLIB (PNG/ZIP) support not available *** FREETYPE2 support not available *** LITTLECMS support not available -------------------------------------------------------------------- 

This is displayed at the end of pinstall install PIL. The question is, why is support not available?

+4
source share
2 answers

It was decided to use the following: http://www.sandersnewmedia.com/why/2012/04/16/installing-pil-virtualenv-ubuntu-1204-precise-pangolin/


For archival purposes, a copy of the message:

The following method should work for both 32-bit and 64-bit systems.

Install build dependencies:

sudo apt-get build-dep python-imaging

Symlink libraries:

 sudo ln -s /usr/lib/`uname -i`-linux-gnu/libfreetype.so /usr/lib/ sudo ln -s /usr/lib/`uname -i`-linux-gnu/libjpeg.so /usr/lib/ sudo ln -s /usr/lib/`uname -i`-linux-gnu/libz.so /usr/lib/ 

Installation:

 pip install PIL 

After the build, you should see something like this:

 -------------------------------------------------------------------- PIL 1.1.7 SETUP SUMMARY -------------------------------------------------------------------- version 1.1.7 platform linux2 2.7.3 (default, Apr 10 2012, 22:21:37) [GCC 4.6.3] -------------------------------------------------------------------- --- TKINTER support available --- JPEG support available --- ZLIB (PNG/ZIP) support available --- FREETYPE2 support available *** LITTLECMS support not available -------------------------------------------------------------------- 
+2
source

Here is a solution that worked for me.

  • Install the following

     sudo apt-get install libjpeg62-dev zlib1g-dev libfreetype6-dev 
  • Open your virtual env

     cd ~/.virtualenvs/{env-name} 
  • Symlink libs for your environment

    For 32-bit systems:

     ln -s /usr/lib/i386-linux-gnu/libz.so ./lib/ ln -s /usr/lib/i386-linux-gnu/libjpeg.so ./lib/ ln -s /usr/lib/i386-linux-gnu/libfreetype.so ./lib/ 

    For 64-bit systems:

     ln -s /usr/lib/x86_64-linux-gnu/libz.so ./lib/ ln -s /usr/lib/x86_64-linux-gnu/libjpeg.so ./lib/ ln -s /usr/lib/x86_64-linux-gnu/libfreetype.so ./lib/ 
  • install PIL (note - if it is already installed, uninstall it and then reinstall it)

     pip install PIL 
+2
source

Source: https://habr.com/ru/post/1413236/


All Articles