ImportError: cannot import name 'python_2_unicode_compatible'

完整报错如下:

(python3.6) root@VPSRawstone01:~/Django2_dailyfresh-python3版本-基本完成# python manage.py makemigrations
Traceback (most recent call last):
  File "manage.py", line 21, in
    main()
  File "manage.py", line 17, in main
    execute_from_command_line(sys.argv)
  File "/root/.virtualenvs/python3.6/lib/python3.6/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line
    utility.execute()
  File "/root/.virtualenvs/python3.6/lib/python3.6/site-packages/django/core/management/__init__.py", line 377, in execute
    django.setup()
  File "/root/.virtualenvs/python3.6/lib/python3.6/site-packages/django/__init__.py", line 24, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/root/.virtualenvs/python3.6/lib/python3.6/site-packages/django/apps/registry.py", line 122, in populate
    app_config.ready()
  File "/root/.virtualenvs/python3.6/lib/python3.6/site-packages/django/contrib/admin/apps.py", line 24, in ready
    self.module.autodiscover()
  File "/root/.virtualenvs/python3.6/lib/python3.6/site-packages/django/contrib/admin/__init__.py", line 26, in autodiscover
    autodiscover_modules('admin', register_to=site)
  File "/root/.virtualenvs/python3.6/lib/python3.6/site-packages/django/utils/module_loading.py", line 47, in autodiscover_modules
    import_module('%s.%s' % (app_config.name, module_to_search))
  File "/root/.virtualenvs/python3.6/lib/python3.6/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "", line 994, in _gcd_import
  File "", line 971, in _find_and_load
  File "", line 955, in _find_and_load_unlocked
  File "", line 665, in _load_unlocked
  File "", line 678, in exec_module
  File "", line 219, in _call_with_frames_removed
  File "/root/.virtualenvs/python3.6/lib/python3.6/site-packages/haystack/admin.py", line 14, in
    from haystack.query import SearchQuerySet
  File "/root/.virtualenvs/python3.6/lib/python3.6/site-packages/haystack/query.py", line 14, in
    from haystack.inputs import AutoQuery, Raw
  File "/root/.virtualenvs/python3.6/lib/python3.6/site-packages/haystack/inputs.py", line 8, in
    from django.utils.encoding import force_text, python_2_unicode_compatible
ImportError: cannot import name 'python_2_unicode_compatible'

解决方案有两个:

给django降等级

pip install django==2.2.10

或者

from django.utils.encoding python_2_unicode_compatible

改成:

from six import python_2_unicode_compatible

你可能感兴趣的:(Django)