使用django-haystack飞快移动使用/错误

时间:2013-12-24 10:21:27

标签: django django-haystack whoosh

我有一个django应用,我正在尝试使用django-haystack,所以如下所示

已安装django-haystack

pip install django-haystack

已安装Whoosh

pip install Whoosh(https://bitbucket.org/mchaput/whoosh/wiki/Home)
            also tried
downloading from https://pypi.python.org/pypi/Whoosh/#downloads

所以,当我尝试pip freeze时,我能够看到输出版本为Whoosh==2.5.6

Django haystack设置

HAYSTACK_SITECONF = 'proj-web.search_sites'
HAYSTACK_SEARCH_ENGINE = 'whoosh'
HAYSTACK_WHOOSH_PATH = (os.path.join(os.path.dirname(__file__), 'search_index/'))

当我试图运行服务器时,我在浏览器中看到以下错误消息

Traceback:
File "/home/user/.virtualenvs/proj/local/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
  103.                     resolver_match = resolver.resolve(request.path_info)
File "/home/user/.virtualenvs/proj/local/lib/python2.7/site-packages/django/core/urlresolvers.py" in resolve
  319.             for pattern in self.url_patterns:
File "/home/user/.virtualenvs/proj/local/lib/python2.7/site-packages/django/core/urlresolvers.py" in url_patterns
  347.         patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/home/user/.virtualenvs/proj/local/lib/python2.7/site-packages/django/core/urlresolvers.py" in urlconf_module
  342.             self._urlconf_module = import_module(self.urlconf_name)
File "/home/user/.virtualenvs/proj/local/lib/python2.7/site-packages/django/utils/importlib.py" in import_module
  35.     __import__(name)
File "/home/user/user/apps/proj-web/proj_name/../proj_name/urls.py" in <module>
  66.   (r'^search/', include('search.urls')),
File "/home/user/.virtualenvs/proj/local/lib/python2.7/site-packages/django/conf/urls/__init__.py" in include
  25.         urlconf_module = import_module(urlconf_module)
File "/home/user/.virtualenvs/proj/local/lib/python2.7/site-packages/django/utils/importlib.py" in import_module
  35.     __import__(name)
File "/home/user/user/apps/proj-web/proj_name/search/urls.py" in <module>
  2. from proj_name.search.views import SiteSearch
File "/home/user/user/apps/proj-web/proj_name/../proj_name/search/views.py" in <module>
  2. from proj_name.haystack.views import SearchView
File "/home/user/user/apps/proj-web/proj_name/../proj_name/haystack/__init__.py" in <module>
  6. from haystack.sites import site
File "/home/user/user/apps/proj-web/proj_name/haystack/__init__.py" in <module>
  60. backend = load_backend(settings.HAYSTACK_SEARCH_ENGINE)
File "/home/user/user/apps/proj-web/proj_name/haystack/__init__.py" in load_backend
  35.         return __import__('haystack.backends.%s_backend' % backend_name, {}, {}, [''])
File "/home/user/user/apps/proj-web/proj_name/haystack/backends/whoosh_backend.py" in <module>
  28.     raise MissingDependency("The 'whoosh' backend requires the installation of 'Whoosh'. Please refer to the documentation.")

Exception Type: MissingDependency at /
Exception Value: The 'whoosh' backend requires the installation of 'Whoosh'. Please refer to the documentation.

那么如何解决上述错误?为什么它要求Whoosh,即使它已经安装了?

修改

(proj)user-ThinkPad-Edge-E430:~/home/user/apps/proj-web/ pip freeze
Django==1.5.5
MySQL-python==1.2.4
PIL==1.1.7
Pillow==2.2.2
South==0.8.4
**Whoosh==2.5.6**
argparse==1.2.1
django-appconf==0.6
django-compressor==1.3
django-haystack==2.1.0
django-mailer==0.1.0
django-pagination==1.0.7
django-tinymce==1.5.2
ipython==1.1.0
psycopg2==2.5.1
six==1.4.1
wsgiref==0.1.2

1 个答案:

答案 0 :(得分:1)

我看到您的项目中有haystack个模块(/home/user/user/apps/proj-web/proj_name/haystack/)。删除此文件夹,激活您的virtualenv并运行:

pip uninstall django-haystack && pip install django-haystack

确保一切正常。

然后尝试像这样配置你的干草堆:

import os
HAYSTACK_CONNECTIONS = {
  'default': {
    'ENGINE': 'haystack.backends.whoosh_backend.WhooshEngine',
    'PATH': os.path.join(os.path.dirname(__file__), 'search_index'),
  },
}