[Django]-Django smart selects on Django version 3.0.1 – error ImportError: cannot import name 'six' from 'django.utils'

6👍

✅

The smart_selects library executes from django.utils import six somewhere in its code, which causes an import error because that package was removed in django 3.0.

If you can’t update the offending package (which you can’t in this case) the only solution would be to patch it yourself, or to wait until the owner of the library patches it.

Patching it yourself is trivial:

  • pip3 install six
  • navigate to your virtual environment’s Django install. Using virtualenv that would be here: /path/to/python/ site-packages/django/utils/__init__.py
  • add import six

Or even better, do it with a bash one-liner:

pip3 install six && echo import six >"$(python3 -c "import sys; print(tuple(filter(lambda x: 'site-packages' in x, sys.path))[0])")"/django/utils/__init__.py

The python3 -c of the script in quotes depends heavily on being able to determine the location of the site_packages directory, and doesn’t work in some virtual environments. YMMV

2👍

i think
you have upgraded Django 2 version to Django 3

for transaction from django 2 to 3 you should make following steps:

replace any statement from on_delete='CASCADE' to on_delete=models.CASCADE

if you had install Django-autocomplete-light
remove it and install it again (i prefer Django-autocomplete-light==3.8.1)

if you had installed djangorestframework
remove it and install it again ( i prefer djangorestframework==3.12.2)

i hope it will success for you and every body

Leave a comment