gpt4 book ai didi

python - 无法让 Elasticsearch 与 Django 一起工作

转载 作者:太空宇宙 更新时间:2023-11-03 14:20:47 25 4
gpt4 key购买 nike

我正在尝试将 Django 和 Haystack 与 Elasticsearch 一起用作 Ubuntu 14.04 的后端。我安装了 Elasticsearch 和 Haystack。

运行 python manage.py runserver 时收到的错误:

me@ubuntu:$ python manage.py runserver
Validating models...

0 errors found
January 31, 2015 - 17:40:37
Django version 1.5.4, using settings 'website_project.settings'
Development server is running at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
Traceback (most recent call last):
File "/home/me/.pythonbrew/pythons/Python-2.7.5/lib/python2.7/wsgiref/handlers.py", line 85, in run
self.result = application(self.environ, self.start_response)
File "/usr/local/lib/python2.7/dist-packages/django/contrib/staticfiles/handlers.py", line 72, in __call__
return self.application(environ, start_response)
File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/wsgi.py", line 243, in __call__
signals.request_started.send(sender=self.__class__)
File "/usr/local/lib/python2.7/dist-packages/django/dispatch/dispatcher.py", line 170, in send
response = receiver(signal=self, sender=sender, **named)
File "/usr/local/lib/python2.7/dist-packages/haystack/__init__.py", line 60, in reset_search_queries
for conn in connections.all():
File "/usr/local/lib/python2.7/dist-packages/haystack/utils/loading.py", line 111, in all
return [self[alias] for alias in self.connections_info]
File "/usr/local/lib/python2.7/dist-packages/haystack/utils/loading.py", line 99, in __getitem__
self._connections[key] = load_backend(self.connections_info[key]['ENGINE'])(using=key)
File "/usr/local/lib/python2.7/dist-packages/haystack/utils/loading.py", line 52, in load_backend
return import_class(full_backend_path)
File "/usr/local/lib/python2.7/dist-packages/haystack/utils/loading.py", line 19, in import_class
module_itself = importlib.import_module(module_path)
File "/usr/local/lib/python2.7/dist-packages/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/usr/local/lib/python2.7/dist-packages/haystack/backends/elasticsearch_backend.py", line 26, in <module>
raise MissingDependency("The 'elasticsearch' backend requires the installation of 'elasticsearch'. Please refer to the documentation.")
MissingDependency: The 'elasticsearch' backend requires the installation of 'elasticsearch'. Please refer to the documentation.

我的 PYTHONPATH 是

home/me/.pythonbrew/pythons/Python-2.7.5/lib:/usr/local/lib/python2.7/dist-packages:/usr/lib/python2.7/dist-packages

我的 INSTALLED_APPS 列表中有 'haystack' 并且具有以下配置:

HAYSTACK_CONNECTIONS = {
'default': {
'ENGINE': 'haystack.backends.elasticsearch_backend.ElasticsearchSearchEngine',
'URL': 'http://127.0.0.1:9200/',
'INDEX_NAME': 'haystack',
},
}

我可以启动 Elasticsearch

sudo service elasticsearch start

当我转到 http://localhost:9200/ 时我明白了

 {
"status" : 200,
"name" : "Stranger",
"version" : {
"number" : "1.1.1",
"build_hash" : "somehash",
"build_timestamp" : "2014-04-16T14:27:12Z",
"build_snapshot" : false,
"lucene_version" : "4.7"
},
"tagline" : "You Know, for Search"
}

我好像安装了 Elasticsearch,所以我不知道为什么会出现

 MissingDependency: The 'elasticsearch' backend requires the installation of 'elasticsearch'. Please refer to the documentation.

错误。

最佳答案

您似乎已经修复了它,但对于 future 的 Google 员工:some people 2014-2015 年左右在 pip 上的 Haystack 版本有问题。将版本修复为 2.1.0 似乎可以修复它,直接从 git 下载 2.4.0 也是如此:

pip install git+https://github.com/django-haystack/django-haystack

更新:pypi 中 haystack 的当前版本(2015 年 11 月),一定要更新!

关于python - 无法让 Elasticsearch 与 Django 一起工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28257502/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com