ImportError: cannot import name ‘python_2_unicode_compatible‘ from ‘django.utils.encoding‘

报错如下:

Traceback (most recent call last):
  File "manage.py", line 22, in <module>
    main()
  File "manage.py", line 18, in main
    execute_from_command_line(sys.argv)
  File "I:\Python\Python3.8\lib\site-packages\django\core\management\__init__.py", line 419, in execute_from_command_line

    utility.execute()
  File "I:\Python\Python3.8\lib\site-packages\django\core\management\__init__.py", line 395, in execute
    django.setup()
  File "I:\Python\Python3.8\lib\site-packages\django\__init__.py", line 24, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "I:\Python\Python3.8\lib\site-packages\django\apps\registry.py", line 114, in populate
    app_config.import_models()
  File "I:\Python\Python3.8\lib\site-packages\django\apps\config.py", line 301, in import_models
    self.models_module = import_module(models_module_name)
  File "I:\Python\Python3.8\lib\importlib\__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 783, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "I:\xadmintest\extra_apps\xadmin\models.py", line 11, in <module>
    from django.utils.encoding import python_2_unicode_compatible, smart_text
ImportError: cannot import name 'python_2_unicode_compatible' from 'django.utils.encoding' (I:\Python\Python3.8\lib\site-
packages\django\utils\encoding.py)


from django.utils.encoding import python_2_unicode_compatible
替换成
from six import python_2_unicode_compatible

你可能感兴趣的:(Python,python,django)