Getting Django to recognize PIL JPEG support

I am running Django 1.4 and PIL 1.1.7 in virtualenv controlled by pip . Whenever I upload a JPEG file through my admin interface, I get the following error: Upload a valid image. The file you uploaded was either not an image or a corrupted image. Upload a valid image. The file you uploaded was either not an image or a corrupted image.

As many Ubuntu users report, when installing PIL I looked impatiently at /usr/lib/ for libjpeg , and its true location was in /usr/lib/i386-linux-gnu/ . This was taken care of; I followed the answers in these posts:

Django ImageField "Upload a valid image. The uploaded file was either not an image or a damaged image."

Why can't I upload jpg files to my Django application using admin /?

Now the final output of the installation is as follows:


 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 available --- JPEG support available --- ZLIB (PNG/ZIP) support available --- FREETYPE2 support available *** LITTLECMS support not available -------------------------------------------------------------------- To add a missing option, make sure you have the required library, and set the corresponding ROOT variable in the setup.py script. To check the build, run the selftest.py script. changing mode of build/scripts-2.7/pilfile.py from 644 to 755 changing mode of build/scripts-2.7/pilfont.py from 644 to 755 changing mode of build/scripts-2.7/pilconvert.py from 644 to 755 changing mode of build/scripts-2.7/pilprint.py from 644 to 755 changing mode of build/scripts-2.7/pildriver.py from 644 to 755 changing mode of /usr/local/bin/pilfile.py to 755 changing mode of /usr/local/bin/pilfont.py to 755 changing mode of /usr/local/bin/pilconvert.py to 755 changing mode of /usr/local/bin/pilprint.py to 755 changing mode of /usr/local/bin/pildriver.py to 755 Successfully installed PIL 

However, Django still does not allow you to upload files other than BMP, which is not acceptable for this project. Unlike the user in the second link, I am not using Apache, so my problem is probably not related. My suspicion is that Django is still using the old PIL installation. The problem is that I do not know where this can be obtained from. The files in ~/.virtualenvs/project/local/lib/python2.7/site-packages seem relevant to me. Any ideas?

EDIT 1: Also note that I tried logging out and logging in to the admin, and setting pillow as in this post: Uploading a JPEG image via Django displays an error

+6
source share
1 answer

It turns out that all this is my mistake due to a misunderstanding of how pip really works. Out of habit, I associate everything and all installations with superuser privileges, which in this case was not only optional, but also a recipe for confusion.

The first time I installed PIL , I did not prefix it with sudo , but I did it every time after. Thus, based on Meitham’s advice, I checked where the import came from. It came from the right place, but I did not have the desired extensions, despite the fact that I did this after installation. In short, I deleted the directory from my package sites, then pip freeze kept telling me that I didn't have a PIL , but sudo pip install told me that I did it.

Lesson learned: virtualenv based on the user's directory, in user privileges. Think twice before combining sudo and pip with the same command .

+2
source

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


All Articles