question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

Hi,

I am running python 3.8, django 3 and django-auditlog 0.4.5 (latest pip and PyCharm know about).

When I try to do a clean python manage.py makemigrations ... I get:

Traceback (most recent call last):
  File "manage.py", line 22, in <module>
    execute_from_command_line(sys.argv)
  File "/home/me/PycharmProjects/myApp/venv/lib/python3.8/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line
    utility.execute()
  File "/home/me/PycharmProjects/myApp/venv/lib/python3.8/site-packages/django/core/management/__init__.py", line 377, in execute
    django.setup()
  File "/home/me/PycharmProjects/myApp/venv/lib/python3.8/site-packages/django/__init__.py", line 24, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/home/me/PycharmProjects/myApp/venv/lib/python3.8/site-packages/django/apps/registry.py", line 114, in populate
    app_config.import_models()
  File "/home/me/PycharmProjects/myApp/venv/lib/python3.8/site-packages/django/apps/config.py", line 211, in import_models
    self.models_module = import_module(models_module_name)
  File "/usr/lib/python3.8/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 783, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/home/me/PycharmProjects/myApp/venv/lib/python3.8/site-packages/auditlog/models.py", line 13, in <module>
    from django.utils.encoding import python_2_unicode_compatible, smart_text
ImportError: cannot import name 'python_2_unicode_compatible' from 'django.utils.encoding' (/home/me/PycharmProjects/myApp/venv/lib/python3.8/site-packages/django/utils/encoding.py)

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:12

github_iconTop GitHub Comments

5reactions
jagadishgvcommented, May 16, 2020

You can fix this by changing the import wherever you get this error,
old code: from django.utils.encoding import python_2_unicode_compatible, smart_text

Updated code:
from django.utils.encoding import smart_text from six import python_2_unicode_compatible

Go to the mentioned path and edit it, or upgrade all libraries, it should solve the issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

python - from django.utils.encoding import ... - Stack Overflow
from django.utils.encoding import python_2_unicode_compatible ImportError: cannot import name 'python_2_unicode_compatible'.
Read more >
cannot import name 'python_2_unicode_compatible' from ...
ImportError : cannot import name 'python_2_unicode_compatible' from 'django.utils.encoding' ... To complete the tutorial, try installing an older ...
Read more >
cannot import name 'force_str' from partially initialized module ...
So far I have dones these things: from django.utils.encoding import force_str. Manuall chagned everything that was force_text_ to force_str.
Read more >
[Django] #16136: Error was: cannot import name utils
mysql' isn't an available database backend. Try using django.db.backends.XXX, where XXX is one of: 'dummy', 'mysql', 'oracle', ...
Read more >
How to Fix ImportError: Cannot Import Name in Python - Rollbar
The Python ImportError: cannot import name error occurs when an imported class is not accessible or is in a circular dependency.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found