问题

Django 3.0 使用 haystack 报错 ImportError: cannot import name 'six' from 'django.utils'

原因

Django 3.x 版本移除了部分用于兼容Python2 的 API
参见 Removed private Python 2 compatibility APIs

解决办法

方案一

安装 six

pip install six

将安装好的 six 文件复制到 'djangoutils 目录下,安装库位于 Python 安装目录下 Lib\site-packages 内或虚拟环境目录 Lib\site-packages 内。

注:
haystack 中的 inputs.py 中使用 django.utils.encoding.python_2_unicode_compatible()six.python_2_unicode_compatible() 的别名,则需要更改 Lib\site-packages\haystack\inputs.py

from django.utils.encoding import force_text, python_2_unicode_compatible

改为

from django.utils.encoding import force_text
from django.utils.six import python_2_unicode_compatible
方案二

使用Django 2.x

Logo

CSDN联合极客时间,共同打造面向开发者的精品内容学习社区,助力成长!

更多推荐