ImportError:无法导入名称'force_unicode'导致了另一个异常

时间:2020-05-11 19:46:04

标签: django python-3.x

我在django应用中正在使用日历,所以我做了:

pip3安装django-scheduler

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

我执行我通常的python3 manage.py runserver的那一刻,由于出现了这么长的异常而失败了:

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'

我以为“哦,不,没问题,我将pip3卸载django_scheduler”

好吧,我做到了(删除了在我的INSTALLED_APPS中添加了“时间表”)并尝试重新运行,并再次遇到相同的错误。那我只是无望地打破了我的整个项目吗?

Python版本是:3.6.8 Django版本:3.0.6

我一直很开心地编码,直到我开始尝试将django库用于我需要实现的日历,而不是仅仅编写自己的:/

1 个答案:

答案 0 :(得分:2)

存在向后兼容的保证,thas不适用于此功能

如果使用最新的Django版本,只需将force_unicode替换为force_text

它在py2和py3上都适用于Django1.11。