Getting error cannot import name 'six' from 'django.utils' when using Django 3.0.0 latest version

前端 未结 5 1821
梦毁少年i
梦毁少年i 2020-12-10 13:18

Currently I have upgraded version of Django 2.2 to 3.0 and suddenly getting error like below.

ImportError: cannot import name \'six\' from \'django.ut

相关标签:
5条回答
  • 2020-12-10 13:52

    Short Answer in Django 3.0 just install six:

    pip install six
    

    And just use it like:

    import six
    
    0 讨论(0)
  • 2020-12-10 14:04

    in order to use the six module you can install it directly using pip and then modify the django-jsonfield package accordingly . What I mean is find the files in the package where there is from django.utils import six and replace them with import six. Then it should be working. I faced the same issue when using djongo with django 3.0. I found the respective file and replaced it with the above suggestion. Please note that it is never recommended to do this if you are working on a production level or enterprise level project. I did it for my pet project.

    0 讨论(0)
  • 2020-12-10 14:05

    In my case it was django-haystac causing this error. It helped me to upgrade the pip package to the newest beta.

    pip install django-haystack==3.0b2
    
    0 讨论(0)
  • Short answer: you might want to abandon django-jsonfield.

    Based on the traceback, you are using the django-jsonfield package [GitHub], and this is a known issue [GitHub-issue]. It depends on the django.utils.six module, but that module has been removed in django-3.0.

    At the moment, you thus can not use django-3.0 with django-jsonfield, and since the last commit to this project is from October 2017, perhaps the project is not that "active" anymore, and it thus might take a very long time (or even never) get fixed. The successor of django-jsonfield is jsonfield2 ([GitHub]). It was made compatible with django-3.0 by a pull request in October (2019) [GitHub-pr].

    0 讨论(0)
  • 2020-12-10 14:09

    A specified in Django 3.0 release note, django.utils.six is removed. In case you need it, it is advised to use pypi packages instead

    In your case, jsonfield package might be replaced by native Django's JSON Field. Another solution would be to fork jsonfield package yourself to solve you issue, or to make a PR on project's repo'

    0 讨论(0)
提交回复
热议问题