• Python3 使用rest_framework 报错 cannot import name 'python_2_unicode_compatible'


    python manage.py makemigrations projectmanage
    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 "D:Program FilesPython3.6libsite-packagesdjangocoremanagement\__init__.py", line 401, in execute_from_command_line
        utility.execute()
      File "D:Program FilesPython3.6libsite-packagesdjangocoremanagement\__init__.py", line 377, in execute
        django.setup()
      File "D:Program FilesPython3.6libsite-packagesdjango\__init__.py", line 24, in setup
        apps.populate(settings.INSTALLED_APPS)
      File "D:Program FilesPython3.6libsite-packagesdjangoapps
    egistry.py", line 114, in populate
        app_config.import_models()
      File "D:Program FilesPython3.6libsite-packagesdjangoappsconfig.py", line 211, in import_models
        self.models_module = import_module(models_module_name)
      File "D:Program FilesPython3.6libimportlib\__init__.py", line 126, in import_module
        return _bootstrap._gcd_import(name[level:], package, level)
      File "<frozen importlib._bootstrap>", line 978, in _gcd_import
      File "<frozen importlib._bootstrap>", line 961, in _find_and_load
      File "<frozen importlib._bootstrap>", line 950, in _find_and_load_unlocked
      File "<frozen importlib._bootstrap>", line 655, in _load_unlocked
      File "<frozen importlib._bootstrap_external>", line 678, in exec_module
      File "<frozen importlib._bootstrap>", line 205, in _call_with_frames_removed
      File "E:WF_WorkHappyAutoTestprojectmanagemodels.py", line 10, in <module>
        from rest_framework.authtoken.models import Token
      File "D:Program FilesPython3.6libsite-packages
    est_frameworkauthtokenmodels.py", line 6, in <module>
        from django.utils.encoding import python_2_unicode_compatible
    ImportError: cannot import name 'python_2_unicode_compatible'

    解决方案:

    #请使用
    
    from six import python_2_unicode_compatible
    
    #替代
    from django.utils.encoding import python_2_unicode_compatible

     再次执行不报错

    python manage.py makemigrations projectmanage
    System check identified some issues:
    Migrations for 'projectmanage':
      projectmanagemigrations001_initial.py
        - Create model Project
  • 相关阅读:
    工程结构
    生活决策
    工作原则概要与列表
    生活原则概要与列表
    在Windows2008下安装SQL Server 2005无法启动服务的解决办法
    MySQL启动提示High Severity Error解决方案
    知乎页面颜色个性化修改
    博客园 CodingLife 模板 翻页样式美化方法
    【翻译】GitHub Pages Basics 基本使用帮助【一】GitHub Pages 是什么?
    【翻译】GitHub Pages Basics 基本使用帮助【首页】
  • 原文地址:https://www.cnblogs.com/ningy1009/p/12802562.html
Copyright © 2020-2023  润新知