0

I am using Heroku to deploy an application that I made with Django 3.1.2 (python 3.6.12), and I am using Cloudinary to store uploaded images.

I am running into a ModuleNotFoundError (shown below) because cloudinary-storage imports django.utils.six, but Django 3.0 does not support django.utils.six.

I have researched a bit, but have not found a working answer. One suggestion was to downgrade to Django2 - but when I did this I started receiving many other errors for other parts of my application so I don't want to go this route if possible.

So now I am trying to figure out a way that I can use Django3 and Cloudinary together, and get around the problem that Django3 does not support django.utils.six. Any help/suggestions would be greatly appreciated

Here is the traceback:

Django Version: 3.1.2
Python Version: 3.6.12
Installed Applications:
['users.apps.UsersConfig',
 'point_system.apps.PointSystemConfig',
 'crispy_forms',
 'django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'cloudinary_storage',
 'cloudinary']
Installed Middleware:
('whitenoise.middleware.WhiteNoiseMiddleware',
 '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 (most recent call last):
  File "/app/.heroku/python/lib/python3.6/site-packages/django/core/handlers/exception.py", line 47, in inner
    response = get_response(request)
  File "/app/.heroku/python/lib/python3.6/site-packages/django/core/handlers/base.py", line 179, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/app/.heroku/python/lib/python3.6/site-packages/django/views/generic/base.py", line 70, in view
    return self.dispatch(request, *args, **kwargs)
  File "/app/.heroku/python/lib/python3.6/site-packages/django/views/generic/base.py", line 98, in dispatch
    return handler(request, *args, **kwargs)
  File "/app/.heroku/python/lib/python3.6/site-packages/django/views/generic/list.py", line 157, in get
    context = self.get_context_data()
  File "/app/point_system/views.py", line 144, in get_context_data
    temp.append(p.image.url)
  File "/app/.heroku/python/lib/python3.6/site-packages/django/db/models/fields/files.py", line 62, in url
    return self.storage.url(self.name)
  File "/app/.heroku/python/lib/python3.6/site-packages/django/utils/functional.py", line 240, in inner
    self._setup()
  File "/app/.heroku/python/lib/python3.6/site-packages/django/core/files/storage.py", line 364, in _setup
    self._wrapped = get_storage_class()()
  File "/app/.heroku/python/lib/python3.6/site-packages/django/core/files/storage.py", line 359, in get_storage_class
    return import_string(import_path or settings.DEFAULT_FILE_STORAGE)
  File "/app/.heroku/python/lib/python3.6/site-packages/django/utils/module_loading.py", line 17, in import_string
    module = import_module(module_path)
  File "/app/.heroku/python/lib/python3.6/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 994, in _gcd_import
    <source code not available>
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
    <source code not available>
  File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
    <source code not available>
  File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
    <source code not available>
  File "<frozen importlib._bootstrap_external>", line 678, in exec_module
    <source code not available>
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
    <source code not available>
  File "/app/.heroku/python/lib/python3.6/site-packages/cloudinary_storage/storage.py", line 17, in <module>
    from django.utils.six.moves.urllib.parse import urlsplit, urlunsplit, unquote

Exception Type: ModuleNotFoundError at /
Exception Value: No module named 'django.utils.six'

Some of the answers that I found that did not work:

ModuleNotFoundError: No module named 'django.utils.six'

ImportError: cannot import name 'six' from 'django.utils'

https://github.com/jazzband/django-sortedm2m/issues/151

Thanks in advance for your help, and please let me know if I need to provide any more information!

Halie
  • 5
  • 1
  • 3
  • What library did you install for Cloudinary support in Django? [The first one I found](https://github.com/tiagocordeiro/dj3-cloudinary-storage) looks like it is specifically for Django 3. – ChrisGPT was on strike Nov 30 '20 at 02:04
  • I was looking at that earlier as well and I installed the one on that page - however, now I am thinking that I have the wrong one in my requirements.txt. I have: "django-cloudinary-storage==0.2.3". Do you think this might be the problem? – Halie Nov 30 '20 at 05:07
  • okay that was it! just had to change the requirements.txt - thanks for your help – Halie Nov 30 '20 at 05:46

1 Answers1

0

I was facing the same issue while upgrading from django 2 to 4. It seems you can import them from python itself no need to use django like this:

from urllib.parse import urlsplit, urlunsplit, unquote

here is the docs

Ahtisham
  • 9,170
  • 4
  • 43
  • 57