[Django]-Python_2_unicode_compatible error

7๐Ÿ‘

โœ…

python_2_unicode_compatible feature has only been added in Django 1.5 version.

https://docs.djangoproject.com/en/dev/ref/utils/#django.utils.encoding.python_2_unicode_compatible

๐Ÿ‘คyetty

34๐Ÿ‘

For the latest Django 3.0.4 , and auditlog try

from six import python_2_unicode_compatible

instead of

from django.utils.six import python_2_unicode_compatible

if it is not install run the below code

pip install six
๐Ÿ‘คgoose

16๐Ÿ‘

try

from django.utils.six import python_2_unicode_compatible

instead of

from django.utils.encoding import python_2_unicode_compatible

this works well for me in Django 1.10.6

๐Ÿ‘คDesperad0

8๐Ÿ‘

I faced the same issue when I upgraded the Django version 2.x to 3.x.

This issue, I faced due to auditlog library.

First, execute the below command

pip uninstall auditlog

then

pip install auditlog3
๐Ÿ‘คSathiamoorthy

6๐Ÿ‘

For me the issue was django-jet package which is not compatible with django3 there is an issue on django-jet github apparently you need to use django-3-jet instead.

๐Ÿ‘คAmir Heshmati

5๐Ÿ‘

I ran into this issue when I wanted to use Django for Graphite.
Turns out I had Django 1.3 installed and my Graphite version was breaking with Django > 1.5, so installing the latest version of the 1.4 branch fixed the problem:

sudo pip install --upgrade 'Django<1.5'
๐Ÿ‘คmre

3๐Ÿ‘

Itโ€™s actually also present in the 1.4 series since 1.4.2. You should really be using the latest 1.4.X release (1.4.10 as of the time of this writing) as earlier versions have known security vulnerabilities.

๐Ÿ‘คTim Graham

1๐Ÿ‘

I was having a same error while i was using the Djnago-multiselect app
that was becuase the app was trying to run the following import

from django.utils.encoding import python_2_unicode_compatible

But in the newer version of django python_2_unicode_compatible is not in the encodings.py but rather in the six module and install if six is not there for you using

pip install six

and then go to the django.utils.encoding.py file
and simply import python_2_unicode_compatible from six like that

from six import python_2_unicode_compatible
๐Ÿ‘คHassan Shahzad

1๐Ÿ‘

I have founded same problem :

from django.utils.encoding import python_2_unicode_compatible
ImportError: cannot import name 'python_2_unicode_compatible'

I have update python version to python3.8, and I worked for me.

๐Ÿ‘คPedrinux81

0๐Ÿ‘

There is an existing package that supports Django 3:
auditlog3

You can install it via pip install auditlog3

0๐Ÿ‘

I have this upgrading Django 1.9 (Python 2.7) to Django 3.2 (Python 3.9).

You can solve this with a bash one liner:

grep -ril "from django.utils.encoding import python_2_unicode_compatible"  your_project_source_code | xargs sed -i 's@from django.utils.encoding import python_2_unicode_compatible@from django.utils.six import python_2_unicode_compatible@g'
๐Ÿ‘คshakaran

0๐Ÿ‘

I was using Django in another computer, but wanted to copy the project with the virtual environment, too. It didnโ€™t work, so I had to recreate the environment.
I got this error because I missed out one package from many:

django-background-tasks

So I had to install this package, and it solved the error.

๐Ÿ‘คChris

0๐Ÿ‘

Step 1: Install six by command: pip install six

Step 2: Go to the file: your_venv/lib/python3.7/site-packages/django/utils/encoding.py

Step 3: Add this line to your file: from six import python_2_unicode_compatible

0๐Ÿ‘

for me replacing
from django.utils.encoding import python_2_unicode_compatible
with
from django.utils.six import python_2_unicode_compatible
with installing below library works!
pip install django-utils-six

๐Ÿ‘คSpring98

Leave a comment