Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django ImportError: cannot import name 'python_2_unicode_compatible'

Tags:

python

django

I'm building a website and I was trying to create a custom user-to-user messaging system so I installed django-messages and maybe a few other things, and suddenly when I tried to run my server I get the following error :

Watching for file changes with StatReloader
Exception in thread django-main-thread:
Traceback (most recent call last):
  File "C:\Users\mertz\AppData\Local\Programs\Python\Python38\lib\threading.py", line 932, in _bootstrap_inner
    self.run()
  File "C:\Users\mertz\AppData\Local\Programs\Python\Python38\lib\threading.py", line 870, in run
    self._target(*self._args, **self._kwargs)
  File "C:\Users\mertz\AppData\Local\Programs\Python\Python38\lib\site-packages\django\utils\autoreload.py", line 53, in wrapper
    fn(*args, **kwargs)
  File "C:\Users\mertz\AppData\Local\Programs\Python\Python38\lib\site-packages\django\core\management\commands\runserver.py", line 109, in inner_run
    autoreload.raise_last_exception()
  File "C:\Users\mertz\AppData\Local\Programs\Python\Python38\lib\site-packages\django\utils\autoreload.py", line 76, in raise_last_exception
    raise _exception[1]
  File "C:\Users\mertz\AppData\Local\Programs\Python\Python38\lib\site-packages\django\core\management\__init__.py", line 357, in execute
    autoreload.check_errors(django.setup)()
  File "C:\Users\mertz\AppData\Local\Programs\Python\Python38\lib\site-packages\django\utils\autoreload.py", line 53, in wrapper
    fn(*args, **kwargs)
  File "C:\Users\mertz\AppData\Local\Programs\Python\Python38\lib\site-packages\django\__init__.py", line 24, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "C:\Users\mertz\AppData\Local\Programs\Python\Python38\lib\site-packages\django\apps\registry.py", line 114, in populate
    app_config.import_models()
  File "C:\Users\mertz\AppData\Local\Programs\Python\Python38\lib\site-packages\django\apps\config.py", line 211, in import_models
    self.models_module = import_module(models_module_name)
  File "C:\Users\mertz\AppData\Local\Programs\Python\Python38\lib\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 "C:\Users\mertz\AppData\Local\Programs\Python\Python38\lib\site-packages\django_messages\models.py", line 9, in <module>
    from django.utils.encoding import python_2_unicode_compatible
ImportError: cannot import name 'python_2_unicode_compatible' from 'django.utils.encoding' (C:\Users\mertz\AppData\Local\Programs\Python\Python38\lib\site-packages\django\utils\encoding.py)

It sounds like chinese to me, I don't understand a single line of this error, can someone help me ? I've made a few researchs, it looks like it's related to a package name six but I was not able to find a solution. I can provide you my code if it's needed but I don't know which file you need so feel free to ask for a file in the comments and I will edit my post accordingly.

Thanks in advance !

like image 780
Julien Mertz Avatar asked Jan 03 '20 18:01

Julien Mertz


1 Answers

You are using Django 3, where all the Python 2 compatibility APIs that used to be bundled with Django were removed. django-messages still depends on these, and is trying and failing to import them.

You either need to downgrade to Django 2.2, or wait for django-messages to be updated for Django 3 support.

This applies for any library in which you get such errors - it means the library is not compatible yet with Django 3.

like image 95
solarissmoke Avatar answered Oct 28 '22 16:10

solarissmoke