python_2_unicode_compatible

from django.utils.encoding import python_2_unicode_compatible
ImportError: cannot import name ‘python_2_unicode_compatible’ from ‘django.utils.encoding’ (/home/marlon/myblog/lib/python3.7/site-packages/django/utils/encoding.py)

try

from django.utils.six import python_2_unicode_compatible

instead of

from django.utils.encoding import python_2_unicode_compatible

and let me know if this works.

django.utils.encoding.python_2_unicode_compatible was removed in Django 3.0. As the release documentation mentions, it was an alias to six.python_2_unicode_compatible. https://docs.djangoproject.com/en/dev/releases/3.0/#removed-private-python-2-compatibility-apis

The suggestion made by @Ookma-Kyi should work.

For those finding this in the future, django.utils.six was dropped in Django 3.0.

I’ve just been using six.

1 Like