Djando 2.0.7 image handling problem on production server

49 views
Skip to first unread message

Asif Khan

unread,
Jul 21, 2018, 11:56:12 AM7/21/18
to Django users
I developed application that uses an ImageField in Django==2.0.7 with Pillow 5.2.0 there is no issue on development machine but facing problem on production server giving "Server Error 500" 
Exception Value: No module named 'PIL' which I have not used or called in my code. I new to Python and Django but seems to me is Django or Pillow problem. If I am not wrong.

the following DEBUG=False production detail 
Internal Server Error: /admin/vv/institutes/add/

ModuleNotFoundError at /admin/vv/institutes/add/
No module named 'PIL'

Request Method: POST
Django Version: 2.0.7
Python Executable: /usr/local/bin/python3
Python Version: 3.6.6
Python Path: ['/home/asifkhan69/webapps/rmsapp', '/home/asifkhan69/webapps/rmsapp/src', '/home/asifkhan69/webapps/rmsapp/lib/python3.6', '/home/asifkhan69/webapps/rmsapp/lib/python3.6/Django-2.0.7-py3.6.egg', '/home/asifkhan69/webapps/rmsapp/lib/python3.6/pytz-2018.5-py3.6.egg', '/usr/local/lib/python36.zip', '/usr/local/lib/python3.6', '/usr/local/lib/python3.6/lib-dynload', '/usr/local/lib/python3.6/site-packages']
Server time: Sat, 21 Jul 2018 13:16:26 +0000
Installed Applications:
['django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'accounts',
'vv']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware']


Traceback:

File "/home/asifkhan69/webapps/rmsapp/lib/python3.6/Django-2.0.7-py3.6.egg/django/core/handlers/exception.py" in inner
  35.             response = get_response(request)

File "/home/asifkhan69/webapps/rmsapp/lib/python3.6/Django-2.0.7-py3.6.egg/django/core/handlers/base.py" in _get_response
  128.                 response = self.process_exception_by_middleware(e, request)

File "/home/asifkhan69/webapps/rmsapp/lib/python3.6/Django-2.0.7-py3.6.egg/django/core/handlers/base.py" in _get_response
  126.                 response = wrapped_callback(request, *callback_args, **callback_kwargs)

File "/home/asifkhan69/webapps/rmsapp/lib/python3.6/Django-2.0.7-py3.6.egg/django/contrib/admin/options.py" in wrapper
  575.                 return self.admin_site.admin_view(view)(*args, **kwargs)

File "/home/asifkhan69/webapps/rmsapp/lib/python3.6/Django-2.0.7-py3.6.egg/django/utils/decorators.py" in _wrapped_view
  142.                     response = view_func(request, *args, **kwargs)

File "/home/asifkhan69/webapps/rmsapp/lib/python3.6/Django-2.0.7-py3.6.egg/django/views/decorators/cache.py" in _wrapped_view_func
  44.         response = view_func(request, *args, **kwargs)

File "/home/asifkhan69/webapps/rmsapp/lib/python3.6/Django-2.0.7-py3.6.egg/django/contrib/admin/sites.py" in inner
  223.             return view(request, *args, **kwargs)

File "/home/asifkhan69/webapps/rmsapp/lib/python3.6/Django-2.0.7-py3.6.egg/django/contrib/admin/options.py" in add_view
  1554.         return self.changeform_view(request, None, form_url, extra_context)

File "/home/asifkhan69/webapps/rmsapp/lib/python3.6/Django-2.0.7-py3.6.egg/django/utils/decorators.py" in _wrapper
  62.             return bound_func(*args, **kwargs)

File "/home/asifkhan69/webapps/rmsapp/lib/python3.6/Django-2.0.7-py3.6.egg/django/utils/decorators.py" in _wrapped_view
  142.                     response = view_func(request, *args, **kwargs)

File "/home/asifkhan69/webapps/rmsapp/lib/python3.6/Django-2.0.7-py3.6.egg/django/utils/decorators.py" in bound_func
  58.                 return func.__get__(self, type(self))(*args2, **kwargs2)

File "/home/asifkhan69/webapps/rmsapp/lib/python3.6/Django-2.0.7-py3.6.egg/django/contrib/admin/options.py" in changeform_view
  1451.             return self._changeform_view(request, object_id, form_url, extra_context)

File "/home/asifkhan69/webapps/rmsapp/lib/python3.6/Django-2.0.7-py3.6.egg/django/contrib/admin/options.py" in _changeform_view
  1483.             if form.is_valid():

File "/home/asifkhan69/webapps/rmsapp/lib/python3.6/Django-2.0.7-py3.6.egg/django/forms/forms.py" in is_valid
  179.         return self.is_bound and not self.errors

File "/home/asifkhan69/webapps/rmsapp/lib/python3.6/Django-2.0.7-py3.6.egg/django/forms/forms.py" in errors
  174.             self.full_clean()

File "/home/asifkhan69/webapps/rmsapp/lib/python3.6/Django-2.0.7-py3.6.egg/django/forms/forms.py" in full_clean
  376.         self._clean_fields()

File "/home/asifkhan69/webapps/rmsapp/lib/python3.6/Django-2.0.7-py3.6.egg/django/forms/forms.py" in _clean_fields
  392.                     value = field.clean(value, initial)

File "/home/asifkhan69/webapps/rmsapp/lib/python3.6/Django-2.0.7-py3.6.egg/django/forms/fields.py" in clean
  578.         return super().clean(data)

File "/home/asifkhan69/webapps/rmsapp/lib/python3.6/Django-2.0.7-py3.6.egg/django/forms/fields.py" in clean
  148.         value = self.to_python(value)

File "/home/asifkhan69/webapps/rmsapp/lib/python3.6/Django-2.0.7-py3.6.egg/django/forms/fields.py" in to_python
  611.         from PIL import Image

Exception Type: ModuleNotFoundError at /admin/vv/institutes/add/
Exception Value: No module named 'PIL'
Request information:
USER: asifkhan


Jason

unread,
Jul 21, 2018, 12:39:36 PM7/21/18
to Django users
sounds like pillow wasn't installed in your prod environment.  how did you set that servcer up?

Asif Khan

unread,
Jul 21, 2018, 12:51:14 PM7/21/18
to Django users
Pillow is install in my production environment and the same Pillow 5.2.0 on both development and production. 

Jason

unread,
Jul 21, 2018, 12:58:55 PM7/21/18
to Django users
are you sure?

open up a python shell on the server and do from PIL import image  If it works, then the problem is somewhere else.  If you get an error, its a missing dependency.

Asif Khan

unread,
Jul 21, 2018, 1:08:03 PM7/21/18
to Django users
Oh dear I checked and found that Pillow was install in Python3.5 where as production setup is for Python3.6 so Pillow was installed by pip3.5 but not with pip3.6 which I have installed now. the problem is resolved. Thanks for make me focus on this.

Melvyn Sopacua

unread,
Jul 21, 2018, 1:36:24 PM7/21/18
to django...@googlegroups.com

On zaterdag 21 juli 2018 19:08:03 CEST Asif Khan wrote:

> Oh dear I checked and found that Pillow was install in Python3.5 where as

> production setup is for Python3.6 so Pillow was installed by pip3.5 but not

> with pip3.6 which I have installed now.

 

Have a look at pyenv. Relying on "versioned commands" goes wrong too often.

 

--

Melvyn Sopacua

mottaz hejaze

unread,
Jul 21, 2018, 10:30:53 PM7/21/18
to django...@googlegroups.com
thats why they invented virtualenv 

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/1932017.Pnh1MIuky5%40fritzbook.
For more options, visit https://groups.google.com/d/optout.

Gerald Brown

unread,
Jul 22, 2018, 1:52:15 AM7/22/18
to django...@googlegroups.com

I use pyvenvwrapper which I find is even better than pyenv.  Once a project is created just enter "workon proj-name" and it will take you to the project directory.  It can be found at: https://github.com/solovyevn/pyvenvwrapper

Melvyn Sopacua

unread,
Jul 22, 2018, 4:47:03 AM7/22/18
to django...@googlegroups.com

On zondag 22 juli 2018 04:30:09 CEST mottaz hejaze wrote:

> thats why they invented virtualenv

 

Just so you know: pyenv is a wrapper around virtualenv, which can pin a project to a python version and just makes virtual environments easier to work with.

 

There's also virtualenvwrapper for somewhat the same thing, except you have to manually select the virtual environment. The combination of the two is a plugin for pyenv, called pyenvwrapper .

 

A different approach to the same problem is mentioned by Gerald Brown.

 

So there are a lot of options to not work with versioned commands and the point I mentioned pyenv for is that it can read the required version for a given project from a single file in the project directory - something virtualenv cannot do.

 

--

Melvyn Sopacua

Reply all
Reply to author
Forward
0 new messages