从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关于循环依赖的问题,但是由于它在代码级别并且可以轻松解决,但是就库而言,什么是解决此问题的最佳方法?

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


  更新(已解决)


根据下面的mfrackowiak的answer,我们必须派生他们的repo,应用patch作为支持,并使用installchanged version。那对我有用

最佳答案

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

关于python - Django2.1.7 ImportError:无法从'django.forms'(/Users/lib/python3.7/site-packages/django/forms/__init__.py)导入名称'util',我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/54705648/

10-09 05:38