cannot import name 'python_2_unicode_compatible' from 'django.utils.encoding'
See original GitHub issueHi,
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:
- Created 4 years ago
- Comments:12
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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.
this solution fixed my issue https://stackoverflow.com/questions/20741754/python-2-unicode-compatible-error/63914949#63914949