Python无法找到Elasticsearch

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/28132841/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 02:46:53  来源:igfitidea点击:

Python unable to find Elasticsearch

pythonpython-2.7elasticsearch

提问by Jorge

I am new to python and I am trying to experience with python and elasticsearch.

我是 python 的新手,我正在尝试使用 python 和 elasticsearch。

I installed python by installing homebrew and running:

我通过安装自制软件并运行来安装 python:

brew install python

This also installed pip. Then when I had pip I ran:

这也安装了pip。然后当我有 pip 时,我跑了:

pip install elasticsearch

This installed elasticsearch. However, When I run the script below:

这安装了elasticsearch。但是,当我运行下面的脚本时:

from elasticsearch import Elasticsearch

es = elasticsearch()

print("hello")

It tells me the following:

它告诉我以下内容:

File "script.py", line 1, in <module>
from elasticsearch import Elasticsearch

ImportError: No module named elasticsearch

导入错误:没有名为 elasticsearch 的模块

Can anyone offer any guidance as to what the issue is?

任何人都可以就问题所在提供任何指导吗?

回答by Zouzias

You should capitalize the 'elasticsearch()'

您应该大写“elasticsearch()”

Quoting from es-python

引用自es-python

# by default we connect to localhost:9200
es = Elasticsearch()

回答by abhishektalluri

Make sure that the python IDLE version in which you run the script is same as the version in which the pip installed elastic search. Sometimes you might run the script in the 3.x version and might have installed elastic search in 2.x version on the same machine.

确保您运行脚本的 python IDLE 版本与 pip 安装弹性搜索的版本相同。有时您可能会在 3.x 版本中运行该脚本,并且可能在同一台机器上安装了 2.x 版本中的弹性搜索。

回答by Bruno Gallien

I had the same issue. I manage to fix the issue by adding in .bash_profile :

我遇到过同样的问题。我设法通过添加 .bash_profile 来解决这个问题:

export PYTHONPATH=/Library/Python/2.7/site-packages

export PYTHONPATH=/Library/Python/2.7/site-packages

回答by fiberair

If you've installed through pip, set/export below environment variable--

如果您已通过pip安装,请在环境变量下方设置/导出--

export PYTHONPATH=/usr/local/lib/python2.7/site-packages

For pyCharm, just add PYTHONPATH=/usr/local/lib/python2.7/site-packages;in Environment variables. You can reach to this setting by "Run-> Edit Configuration". Click apply and it should work fine.

对于pyCharm,只需添加PYTHONPATH=/usr/local/lib/python2.7/site-packages; 环境变量中。您可以通过“运行-> 编辑配置”访问此设置。单击应用,它应该可以正常工作。