错误:'elasticsearch'后端需要安装'requests'。我该如何修复它?

7
在使用 Haystack 和 Elasticsearch 支持应用程序时,运行 "python manage.py rebuild_index" 命令时出现了问题。
Python 版本为 2.7,Django 版本为 1.6.2,Haystack 版本为 2.1.0,Elasticsearch 版本为 1.0。
以下是出现的错误:
Traceback (most recent call last): File "manage.py", line 10, in execute_from_command_line(sys.argv) File "/usr/lib/python2.7/site-packages/django/core/management/__init__.py", line 399, in execute_from_command_line utility.execute() File "/usr/lib/python2.7/site-packages/django/core/management/__init__.py", line 392, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "/usr/lib/python2.7/site-packages/django/core/management/base.py", line 242, in run_from_argv self.execute(*args, **options.__dict__) File "/usr/lib/python2.7/site-packages/django/core/management/base.py", line 285, in execute output = self.handle(*args, **options) File "/usr/lib/python2.7/site-packages/haystack/management/commands/rebuild_index.py", line 15, in handle call_command('clear_index', **options) File "/usr/lib/python2.7/site-packages/django/core/management/__init__.py", line 159, in call_command return klass.execute(*args, **defaults) File "/usr/lib/python2.7/site-packages/django/core/management/base.py", line 285, in execute output = self.handle(*args, **options) File "/usr/lib/python2.7/site-packages/haystack/management/commands/clear_index.py", line 48, in handle backend = connections[backend_name].get_backend() File "/usr/lib/python2.7/site-packages/haystack/utils/loading.py", line 98, in __getitem__ self._connections[key] = load_backend(self.connections_info[key]['ENGINE'])(using=key) File "/usr/lib/python2.7/site-packages/haystack/utils/loading.py", line 51, in load_backend return import_class(full_backend_path) File "/usr/lib/python2.7/site-packages/haystack/utils/loading.py", line 18, in import_class module_itself = importlib.import_module(module_path) File "/usr/lib/python2.7/site-packages/django/utils/importlib.py", line 40, in import_module __import__(name) File "/usr/lib/python2.7/site-packages/haystack/backends/elasticsearch_backend.py", line 21, in raise MissingDependency("The 'elasticsearch' backend requires the installation of 'requests'.") haystack.exceptions.MissingDependency: The 'elasticsearch' backend requires the installation of 'requests'。
我已经安装了运行这些应用程序所需的所有软件包,但是它还在要求 requests。那是什么?

顺便问一下,你是如何安装django-haystack的? - Aamir Rind
你确定已经安装了requests吗?尝试运行 pip install requests。另外,如果你没有在虚拟环境中运行这个程序,建议你使用虚拟环境来更好地管理依赖项并避免项目之间的冲突。 - patsweet
3个回答

24

只是去做

pip install pyelasticsearch

1
这个技巧对我很有用。上述命令安装了以下软件包: Installing collected packages: certifi, urllib3, elasticsearch, simplejson, six, pyelasticsearch因此问题可能是由于缺少依赖项(我强烈怀疑是urllib3)引起的。 - JDP

2
如果你只是通过pip安装requests模块,那么这个错误就会消失。

1
不幸的是,requests已经安装了(甚至在虚拟环境中卸载/重新安装以确保),但它仍然无法工作。 - vinyll
可能是虚拟环境的问题。请确保环境已激活,或者在安装了 haystack 的位置安装 requests。 - Aamir Rind

0

pip install "elasticsearch>=7,<8"


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接