Pil or Pillow on Heroku dosen't work - django

I tried to migrate my django app to heroku, but Pil library can't work on heroku.
My requirements.txt below works fine on other container based platform, but not on heroku.
Django==1.4.6
Pil
django-mptt==0.5.2
...
I've checked some QAs on stackoverflow and added some changes and reinstall Pil, Pillow or these some forks below
-e hg+https://bitbucket.org/etienned/pil-2009-raclette/#egg=PIL
-e git://github.com/errkk/gitpil.git#egg=PIL
Pillow==1.7.8
but doen't work fine with these errors.
'decorder zip not available' 'decoder jpeg not available'.
Do you have any ideas to fix this?
Thanks,

Related

No module named 'channels'

I am trying to install channels, following their tutorial(channels tutorial) but when I try to run the server I get the error: No module named 'channels'.
I have tried reinstalling it, moving the app to the top of the list of "INSTALLED_APPS" but it still does not work.
I have installed python 3.7 and django 2.1.3
There is no need to reinstall the python Or django. You just forgot to install channels. Follow Channel 2.1.7 installation
Try python -m pip install -U channels
this will fix your issue.
It seems the problem was it conflicted with another library, probably whitenoise. I created a new clear env and it works fine now.
I have also getting this issue:
you need to run python -m pip install -U channels. This might solve the issue.

No module named PIL in heroku though it is installed

I have been trying to deploy a Django application on Heroku.
Some background - I hadn't used virtual environment while building the application but while deploying it, I had to use it. I'm following this tutorial for deployment. https://medium.com/agatha-codes/9-straightforward-steps-for-deploying-your-django-app-with-heroku-82b952652fb4
Now I'm stuck in step-6. After creating a virtual environment I have freezed the dependencies into requirements.txt.
But when I open the deployed URL it says
ImportError at /
No module named PIL
though Pillow has been installed, it is there in requirements.txt and runs fine when hosted on a local server.
This is my requirements.txt.
certifi==2018.4.16
dj-database-url==0.5.0
Django==1.11.14
django-heroku==0.3.1
gunicorn==19.9.0
packaging==17.1
Pillow==5.2.0
pip-review==1.0
pipenv==2018.7.1
pkg-resources==0.0.0
psycopg2==2.7.5
pyparsing==2.2.0
pytz==2018.5
six==1.11.0
virtualenv==16.0.0
virtualenv-clone==0.3.0
whitenoise==3.3.1
Please help me with this.
Heroku? Access your application and manually run pip install -r requirements.txt, then turn the application off and back on again.
I had this problem before, this step solved my problem.
If you are doing this in your view
import PIL
do this
import Image
In my case I solved this issue by installing 'Pillow'... just try pip/pip3 install Pillow and add it to your requirements.txt file.

Pillow installation not recognized in Django through Apache

When deploying my project through Apache wsgi, using a virtualenv on Ubuntu Server VM, I get the following on error on /var/log/apache2/error.log:
ImportError: Photologue was unable to import Python Imaging Library. Please confirm it's installed and available on your current Python path.
Setup:
Django==1.6.6
django-photologue==2.3
Pillow==2.5.1
However, I have been able to run the project with the same configuration in Ubuntu Desktop VM (for development). For Ubuntu Server VM I followed the same procedure:
Installed dependent image libraries (libjpeg8-dev, etc) through apt-get
pip install pillow, in virtualenv, it showed --- JPEG support available
Ran this with no problems:
manage.py shell
from PIL import Image
im = Image.open("file.jpg")
im.show()
Used django's server with no problem, it showed the login screen:
manage.py runserver
For sanity's sake, I uninstalled pillow, running manage.py runserver showed the same import error. I reinstalled pillow and the error went away in the django server
Now, the issues arise when I try to access the website on the browser through apache. I go to the servername to get the actual django website and keep getting a 500 Internal Server Error on the browser and the import error on apache log.
The only thing I can think of is that in manage.py shell I can't do "import Image". However, photologue has a try/except import in which it will do "from PIL import Image" in case of an exception with "import Image", which covers that case.
I found the answer, posting it here since it was not entirely obvious.
This is a more subtle case of PIL not being able to link against the directories in apt-get. The answer from the ubuntu forums solves this issue.
sudo ln -s /lib/x86_64-linux-gnu/libz.so.1 /lib/
sudo ln - /usr/lib/x86_64-linux-gnu/libfreetype.so.6 /usr/lib/
sudo ln -s /usr/lib/x86_64-linux-gnu/libjpeg.so.62 /usr/lib/
However, I was not able to run the django proyect with pillow. I had to use PIL, which is annoying:
pip uninstall pillow
pip install PIL --allow-external PIL --allow-unverified PIL

Pythonanywhere Pillow install not working

I have loaded my django app onto Pythonanywhere and when running through my functions, I learned I cannot upload images through the Admin since I moved into production. I am getting this error:
Neither Pillow nor PIL could be imported: No module named 'Image'
Which from prior experience means Pillow isn't installed. So I opened a bash console and ran
pip3 install --user Pillow
and it said it installed correctly, and I did reload my app but it still doesn't work
(same error). What went wrong?
Thanks in advance, Conner
Also, I did see this question on their forums: https://www.pythonanywhere.com/forums/topic/1247/
UPDATE:
Tried uninstalling Pillow and re-installing, then restarting web server. Still not working.

Uploading a JPEG image via Django displays error

I'm running a Django app inside a virtualenv on Ubuntu with NGINX/FastCGI and trying to upload a JPG image to the Django admin app.
I'm getting this error: "Upload a valid image. The file you uploaded was either not an image or a corrupted image." I can upload a GIF image, so it's only JPEG that's causing the problem.
Here's what I've tried so far:
1) Install libjpeg62-dev before PIL
pip uninstall pil
sudo apt-get libjpeg62-dev
pip install pil
At the end of the PIL install, I see:
PIL 1.1.7 SETUP SUMMARY
--------------------------------------------------------------------
version 1.1.7
platform linux2 2.6.5 (r265:79063, Apr 16 2010, 13:09:56)
[GCC 4.4.3]
--------------------------------------------------------------------
*** TKINTER support not available
--- JPEG support available
--- ZLIB (PNG/ZIP) support available
--- FREETYPE2 support available
*** LITTLECMS support not available
So it looks like JPEG support is there. I've also done the manual test to verify and it verified:
>>> from PIL import Image
>>> trial_image=Image.open("/path/to/my/image.png")
>>> trial_image.verify()
2) Similar to approach #1 above, but manually specifying the JPG_ROOT:
pip uninstall pil
sudo apt-get libjpeg62-dev
pip install --no-install pil
vi /path/to/virtualenv/build/PIL/setup.py (JPG_ROOT = libinclude("/usr/lib"))
pip install pil
3) Try my luck with Pillow (a PIL fork)
pip uninstall pil
sudo apt-get libjpeg62-dev
pip install pillow
I'm running Django under I've also trying stopping & starting the nginx service after each time installing PIL.
So far none of the above approaches have gotten me past the above error message in my Django app on Ubuntu. I can upload the same JPG image just fine on my local dev box (Mac OSX 10.6.5) running the same Django app, so I know it's something with my deployment on Ubuntu.
Any help would be appreciated!
Well what do you know, I decided to log out of the Django admin and log back in....suddenly it works fine! Sheesh. The last thing I tried was approach #2 above so if anyone is having this problem, that's your best solution.
You were close. But the library required was different.
The answer, helped me, is here https://stackoverflow.com/a/23445746/1478569