Django2.1.7 ImportError:无法从'django.forms'(/Users/lib/python3.7/site-packages/django/forms/__init__.py)导入名称'util'

时间:2019-02-15 08:56:56

标签: python django python-3.x django-forms importerror

在从Django1.5迁移到Django2.1.7的过程中,尝试启动服务器时,库函数中遇到了隐式导入错误。

Traceback (most recent call last):
Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x10945f950>
Traceback (most recent call last):
  File "/Users/MAK/Envs/lifemed3/lib/python3.7/site-packages/django/utils/autoreload.py", line 225, in wrapper
    fn(*args, **kwargs)
  File "/Users/MAK/Envs/lifemed3/lib/python3.7/site-packages/django/core/management/commands/runserver.py", line 109, in inner_run
    autoreload.raise_last_exception()
  File "/Users/MAK/Envs/lifemed3/lib/python3.7/site-packages/django/utils/autoreload.py", line 248, in raise_last_exception
    raise _exception[1]
  File "/Users/MAK/Envs/lifemed3/lib/python3.7/site-packages/django/core/management/__init__.py", line 337, in execute
    autoreload.check_errors(django.setup)()
  File "/Users/MAK/Envs/lifemed3/lib/python3.7/site-packages/django/utils/autoreload.py", line 225, in wrapper
    fn(*args, **kwargs)
  File "/Users/MAK/Envs/lifemed3/lib/python3.7/site-packages/django/__init__.py", line 24, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/Users/MAK/Envs/lifemed3/lib/python3.7/site-packages/django/apps/registry.py", line 89, in populate
    app_config = AppConfig.create(entry)
  File "/Users/MAK/Envs/lifemed3/lib/python3.7/site-packages/django/apps/config.py", line 90, in create
    module = import_module(entry)
  File "/Users/MAK/Envs/lifemed3/lib/python3.7/importlib/__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 "/Users/MAK/Envs/lifemed3/lib/python3.7/site-packages/json_field/__init__.py", line 1, in <module>
    from json_field.fields import JSONField
  File "/Users/MAK/Envs/lifemed3/lib/python3.7/site-packages/json_field/fields.py", line 4, in <module>
    from json_field.forms import JSONFormField
  File "/Users/MAK/Envs/lifemed3/lib/python3.7/site-packages/json_field/forms.py", line 5, in <module>
    from django.forms import fields, util
ImportError: cannot import name 'util' from 'django.forms' (/Users/MAK/Envs/lifemed3/lib/python3.7/site-packages/django/forms/__init__.py)

我们已经检查了此answer关于循环依赖的问题,但是由于它在代码级别并且可以轻松解决,但是就库而言,什么是解决此问题的最佳方法?

仅供参考:我们正在将Django2.1.7从python 2.7和Django 1.5.5迁移到python3.7

  

更新(已解决)

根据下面的mfrackowiak的answer,我们必须派出他们的repo,应用patch获得支持,并从install获得changed version。然后对我有用

2 个答案:

答案 0 :(得分:0)

我找到了这两个软件包:

  • 如果这是您正在使用的软件包django-json-field,请查看2014年的最新版本,因此,我很确定此软件包与Django 2.0

  • 如果jsonfield是您的软件包,那么即使他们不支持Django 2.0。他们有1.8到1.11

在您的代码中张贴您打算使用该程序包执行的操作,然后我可能会为您提供一个自定义解决方案或程序包,该程序或程序包实际上支持2.0并且可以正常工作。

答案 1 :(得分:0)

似乎package长期未维护,处理此错误的最佳方法是查找alternatives或只是分叉存储库并自己更新它,这样仍然可以工作(可能比调整另一个库的代码库容易)。