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
Python unable to find Elasticsearch
提问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
回答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; 在环境变量中。您可以通过“运行-> 编辑配置”访问此设置。单击应用,它应该可以正常工作。