Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ImportError: cannot import name 'force_unicode' caused another exception

I was playing with calendars in my django app so I did a:

pip3 install django-scheduler

(https://github.com/llazzaro/django-scheduler)

The minute I did my usual python3 manage.py runserver it failed with this long exception:

Exception in thread django-main-thread:
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/dist-packages/filer/utils/compatibility.py", line 71, in <module>
    from django.utils.encoding import force_unicode  # noqa
ImportError: cannot import name 'force_unicode'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.6/threading.py", line 916, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.6/threading.py", line 864, in run
    self._target(*self._args, **self._kwargs)
  File "/home/shane/.local/lib/python3.6/site-packages/django/utils/autoreload.py", line 53, in wrapper
    fn(*args, **kwargs)
  File "/home/shane/.local/lib/python3.6/site-packages/django/core/management/commands/runserver.py", line 109, in inner_run
    autoreload.raise_last_exception()
  File "/home/shane/.local/lib/python3.6/site-packages/django/utils/autoreload.py", line 76, in raise_last_exception
    raise _exception[1]
  File "/home/shane/.local/lib/python3.6/site-packages/django/core/management/__init__.py", line 357, in execute
    autoreload.check_errors(django.setup)()
  File "/home/shane/.local/lib/python3.6/site-packages/django/utils/autoreload.py", line 53, in wrapper
    fn(*args, **kwargs)
  File "/home/shane/.local/lib/python3.6/site-packages/django/__init__.py", line 24, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/home/shane/.local/lib/python3.6/site-packages/django/apps/registry.py", line 114, in populate
    app_config.import_models()
  File "/home/shane/.local/lib/python3.6/site-packages/django/apps/config.py", line 211, in import_models
    self.models_module = import_module(models_module_name)
  File "/usr/lib/python3.6/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 994, in _gcd_import
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 678, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/usr/local/lib/python3.6/dist-packages/filer/models/__init__.py", line 2, in <module>
    from .clipboardmodels import *  # noqa
  File "/usr/local/lib/python3.6/dist-packages/filer/models/clipboardmodels.py", line 8, in <module>
    from ..utils.compatibility import python_2_unicode_compatible
  File "/usr/local/lib/python3.6/dist-packages/filer/utils/compatibility.py", line 86, in <module>
    from django.utils.encoding import python_2_unicode_compatible  # noqa
ImportError: cannot import name 'python_2_unicode_compatible'

I thought 'oh no, no problem I will just pip3 uninstall django_scheduler'

Well, I did that (removed the addition of 'schedule' to my INSTALLED_APPS) and tried to rerun, and got the same error again. So did I just hopelessly break my entire project?

Python version is: 3.6.8 Django Version: 3.0.6

I was happily coding till I had this brainwave of trying to use a django library for the calendar I need to implement instead of just writing my own :/

like image 663
Codejoy Avatar asked May 11 '20 19:05

Codejoy


1 Answers

there is a backward compatibility promise thas doesn't apply to this function

just replace force_unicode with force_text if you use recent Django releases.

it worked for Django1.11 on both py2 and py3.

like image 68
morteza kavakebi Avatar answered Oct 17 '22 10:10

morteza kavakebi