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 <module>
    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 "<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 "/root/.virtualenvs/python3.6/lib/python3.6/site-packages/haystack/admin.py", line 14, in <module>
    from haystack.query import SearchQuerySet
  File "/root/.virtualenvs/python3.6/lib/python3.6/site-packages/haystack/query.py", line 14, in <module>
    from haystack.inputs import AutoQuery, Raw
  File "/root/.virtualenvs/python3.6/lib/python3.6/site-packages/haystack/inputs.py", line 8, in <module>
    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

发布了790 篇原创文章 · 获赞 365 · 访问量 168万+
展开阅读全文

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 技术黑板 设计师: CSDN官方博客

分享到微信朋友圈

×

扫一扫,手机浏览