Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
405 views
in Technique[技术] by (71.8m points)

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

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.utils'

I have checked Traceback is like below.

Traceback (most recent call last):
  File "c:Usersadmin.vscodeextensionsms-python.python-2019.11.50794pythonFilesptvsd_launcher.py", line 43, in <module>
    main(ptvsdArgs)
  File "c:Usersadmin.vscodeextensionsms-python.python-2019.11.50794pythonFileslibpythonold_ptvsdptvsd\__main__.py", line 432, in main
    run()
  File "c:Usersadmin.vscodeextensionsms-python.python-2019.11.50794pythonFileslibpythonold_ptvsdptvsd\__main__.py", line 316, in run_file
    runpy.run_path(target, run_name='__main__')
  File "C:Python37Lib
unpy.py", line 263, in run_path
    pkg_name=pkg_name, script_name=fname)
  File "C:Python37Lib
unpy.py", line 96, in _run_module_code
    mod_name, mod_spec, pkg_name, script_name)
  File "C:Python37Lib
unpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "D:productionmyprojecterp_projectmanage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "d:productionmyprojectvenvlibsite-packagesdjangocoremanagement\__init__.py", line 401, in execute_from_command_line
    utility.execute()
  File "d:productionmyprojectvenvlibsite-packagesdjangocoremanagement\__init__.py", line 377, in execute
    django.setup()
  File "d:productionmyprojectvenvlibsite-packagesdjango\__init__.py", line 24, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "d:productionmyprojectvenvlibsite-packagesdjangoapps
egistry.py", line 92, in populate
    app_config = AppConfig.create(entry)
  File "d:productionmyprojectvenvlibsite-packagesdjangoappsconfig.py", line 90, in create
    module = import_module(entry)
  File "d:productionmyprojectvenvlibimportlib\__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 728, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "d:productionmyprojectvenvlibsite-packagespost_office\__init__.py", line 3, in <module>
    from .backends import EmailBackend
  File "d:productionmyprojectvenvlibsite-packagespost_officeackends.py", line 6, in <module>
    from .settings import get_default_priority
  File "d:productionmyprojectvenvlibsite-packagespost_officesettings.py", line 101, in <module>
    context_field_class = import_attribute(CONTEXT_FIELD_CLASS)
  File "d:productionmyprojectvenvlibsite-packagespost_officecompat.py", line 45, in import_attribute
    module = importlib.import_module(module_name)
  File "d:productionmyprojectvenvlibimportlib\__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "d:productionmyprojectvenvlibsite-packagesjsonfield\__init__.py", line 1, in <module>
    from .fields import JSONField, JSONCharField  # noqa
  File "d:productionmyprojectvenvlibsite-packagesjsonfieldfields.py", line 21, in <module>
    from .encoder import JSONEncoder
  File "d:productionmyprojectvenvlibsite-packagesjsonfieldencoder.py", line 2, in <module>
    from django.utils import six, timezone
ImportError: cannot import name 'six' from 'django.utils' (d:productionmyprojectvenvlibsite-packagesdjangoutils\__init__.py)

I have checked in folder Libsite-packagesdjangoutils and not found and six.py file but still from Libsite-packagesjsonfieldencode.py containing line from django.utils import six, timezone which trying to import six but not able to find.

Earlier version of django containing six.py file in folder Libsite-packagesdjangoutils.

Any idea how to solve this ?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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 .

At the moment, you thus can not use with , 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 is ([GitHub]). It was made compatible with by a pull request in October (2019) [GitHub-pr].


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...