ImportError:无法导入名称连接

问题描述 投票:2回答:3

我想在我的django应用程序中包含全文搜索。我正在使用whoosh-haystack。当我在我安装的应用程序中包含whoosh和haystack,并执行命令./manage.py时,我收到导入错误。谁能解决这个问题。

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'whoosh',
    'haystack',
    'galleryApp',
    'galleryAdmin',
]

我得到的错误是

Traceback (most recent call last):
  File "./manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 353, in execute_from_command_line
    utility.execute()
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 327, in execute
    django.setup()
  File "/usr/local/lib/python2.7/dist-packages/django/__init__.py", line 18, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/usr/local/lib/python2.7/dist-packages/django/apps/registry.py", line 115, in populate
    app_config.ready()
  File "/usr/local/lib/python2.7/dist-packages/django/contrib/admin/apps.py", line 22, in ready
    self.module.autodiscover()
  File "/usr/local/lib/python2.7/dist-packages/django/contrib/admin/__init__.py", line 26, in autodiscover
    autodiscover_modules('admin', register_to=site)
  File "/usr/local/lib/python2.7/dist-packages/django/utils/module_loading.py", line 50, in autodiscover_modules
    import_module('%s.%s' % (app_config.name, module_to_search))
  File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
  File "/usr/local/lib/python2.7/dist-packages/haystack/admin.py", line 13, in <module>
    from haystack import connections
ImportError: cannot import name connections
django django-haystack whoosh
3个回答
4
投票

haystack是相互矛盾的django-haystack。 (重新)移动它将解决问题。

有关详细信息,请参阅chat


1
投票

检查python __init__.py文件夹中是否有sitepackages/haystack文件。这可能是由于缺乏__init__.py__init__.py具有连接属性。如果没有,请尝试从github源卸载并安装/手动编写__init__.py文件。


0
投票

以上对我不起作用。

对我有用的是:

  • pip uninstall haystack
  • pip uninstall django-haystack
  • pip install django-haystack
© www.soinside.com 2019 - 2024. All rights reserved.