Django 3.0 使用 haystack 报错
date
Apr 6, 2020
slug
5589754232334336
status
Published
tags
summary
type
Post
问题
Django 3.0 使用
haystack 报错 ImportError: cannot import name 'six' from 'django.utils'原因
Django 3.x 版本移除了部分用于兼容Python2 的 API
参见 Removed private Python 2 compatibility APIs
解决办法
方案一
安装
sixpip install six
将安装好的
six 文件复制到 'django 的 utils 目录下,安装库位于 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.pyfrom 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