Why this error/exception?
From django-3.0release notes,
django.utils.six– Remove usage of this vendored library or switch to six.
means, django.utils.six module was removed from django-3.0 onwards.
My codebase isn’t using “django.utils.six” module, then why this error?
This import error could be raised because of two reasons,
- Most importantly, any of your installed packages are using the
django.utils.sixmodule - or maybe your codebase using the
django.utils.sixmodule
NOTE: Most of the time the first reason is the villain 😖😖
How can I identify which package is causing the error/exception?
The easy way is, look into your last few lines of error traceback, and it will tell you which package is causing the exceptions.
Examples
Corsheaders
In this example, corsheaders module caused the the import error
File "/path-to-project/project/venv/lib/python3.7/site-packages/corsheaders/__init__.py", line 1, in
from .checks import check_settings # noqa: F401
File "/path-to-project/project/venv/lib/python3.7/site-packages/corsheaders/checks.py", line 7, in
from django.utils import six
Example-2
In this example, jsonfield module caused the the import error
File "d:\production\myproject\venv\lib\site-packages\jsonfield\fields.py", line 21, in
from .encoder import JSONEncoder
File "d:\production\myproject\venv\lib\site-packages\jsonfield\encoder.py", line 2, in
from django.utils import six, timezone
ImportError: cannot import name 'six' from 'django.utils' (d:\production\myproject\venv\lib\site-packages\django\utils\__init__.py)
Example-3
In this example parler module caused the import error
...
File "/path/to/project/venv/lib/python3.8/site-packages/parler/utils/conf.py", line 10, in
from django.utils import six
ImportError: cannot import name 'six' from 'django.utils' (/path/to/project/venv/lib/python3.8/site-packages/django/utils/__init__.py)
Example-4
In this example django_mysql module caused the import error
File "/home/jerin/.virtualenvs/webscraperio/lib/python3.6/site-packages/django_mysql/checks.py", line 9, in
from django_mysql.utils import collapse_spaces
File "/home/jerin/.virtualenvs/webscraperio/lib/python3.6/site-packages/django_mysql/utils.py", line 17, in
from django.utils import six
ImportError: cannot import name 'six'
What is the solution?
If the error raised because of some third-party packages like django-cors-headers,django-jsonfield, etc upgrade the corresponding package versions to latest versions. If you are already using the latest version, report an issue with the developer.
If the error raised because from your codebase, use six package instead of django.utils.six module