Python中安装xadmin时遇到ImportError: cannot import name 'smart_unicode'如何解决
null
Python中安装xadmin时遇到ImportError: cannot import name 'smart_unicode’如何解决
1 回复
这个报错是因为新版本Django移除了smart_unicode,而xadmin还在引用它。有几种解决方法:
方法1:修改xadmin源码(推荐)
在xadmin安装目录中找到出问题的文件,把from django.utils.encoding import smart_unicode改成:
try:
from django.utils.encoding import smart_unicode
except ImportError:
from django.utils.encoding import smart_text as smart_unicode
方法2:使用兼容版本 如果你用的Django 3.0+,需要安装兼容版本:
pip install git+https://github.com/sshwsfc/xadmin.git@django2
方法3:降级Django 如果项目允许,可以降级到Django 2.x:
pip install django==2.2.*
我通常用方法1,改几行代码就能搞定。xadmin本身已经很久没更新了,遇到这种兼容性问题很正常。
总结:改源码引用或者用兼容分支。

