2

当我运行默认服务器时,安装在 virtualenv 中的 Django-nose 在 runner.py 中给出“ImportError:无法导入名称设置”。在进行回溯时,我得到了这个:

File "/home/sid/.virtualenvs/workbench/local/lib/python2.7/site-packages/django/core/management/base.py", line 222, in run_from_argv
    self.execute(*args, **options.__dict__)

  File "/home/sid/.virtualenvs/workbench/local/lib/python2.7/site-packages/django/core/management/base.py", line 250, in execute
    translation.activate('en-us')

  File "/home/sid/.virtualenvs/workbench/local/lib/python2.7/site-packages/django/utils/translation/__init__.py", line 90, in activate
    return _trans.activate(language)

  File "/home/sid/.virtualenvs/workbench/local/lib/python2.7/site-packages/django/utils/translation/trans_real.py", line 183, in activate
    _active.value = translation(language)

  File "/home/sid/.virtualenvs/workbench/local/lib/python2.7/site-packages/django/utils/translation/trans_real.py", line 172, in translation
    default_translation = _fetch(settings.LANGUAGE_CODE)

  File "/home/sid/.virtualenvs/workbench/local/lib/python2.7/site-packages/django/utils/translation/trans_real.py", line 154, in _fetch
    app = import_module(appname)

  File "/home/sid/.virtualenvs/workbench/local/lib/python2.7/site-packages/django/utils/importlib.py", line 35, in import_module
    __import__(name)

  File "/home/sid/.virtualenvs/workbench/local/lib/python2.7/site-packages/django_nose/__init__.py", line 5, in <module>
    from django_nose.runner import BasicNoseRunner, NoseTestSuiteRunner

  File "/home/sid/.virtualenvs/workbench/local/lib/python2.7/site-packages/django_nose/runner.py", line 19, in <module>
    from django import setup
ImportError: cannot import name setup
`

我在 django 文档上找到了关于django.setup()的内容,尽管像这样的大多数问题都有 pythonic 问题而不是 Django

4

2 回答 2

6

Django 1.5 已经有一段时间不被支持了,并且 django-nose 在他们最近的版本中已经放弃了兼容性。django.setup()在 Django 1.7 中添加。

您需要升级 Django 或将 django-nose 降级到兼容版本。我建议将 Django 升级到受支持的版本,以便您收到错误修复和安全更新。

于 2016-07-18T14:58:06.707 回答
0

Django-nose 在1.4.4 版本中放弃了对 Django 1.5 的支持。

我可以通过在 1.4.3 安装 django-nose 来解决这个问题。

pip install django-nose==1.4.3
于 2020-05-22T16:13:07.140 回答