Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python unable to find Elasticsearch

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

I installed python by installing homebrew and running:

brew install python

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

pip install elasticsearch

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

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

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

like image 609
Jorge Avatar asked Jan 25 '15 03:01

Jorge


People also ask

What is elasticsearch in python?

What is ElasticSearch? ElasticSearch (ES) is a distributed and highly available open-source search engine that is built on top of Apache Lucene. It's an open-source which is built in Java thus available for many platforms. You store unstructured data in JSON format which also makes it a NoSQL database.

How do I check Elasticsearch version in Python?

OPTION 1: Check Version using Curl from Command Line In this example, Elasticsearch is running locally on the default port so our HTTP request will be to http://localhost:9200 . If Elasticsearch was running on a different server your HTTP request would take the form http://YOURDOMAIN.com:9200 .


2 Answers

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

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.

like image 116
fiberair Avatar answered Oct 22 '22 21:10

fiberair


You should capitalize the 'elasticsearch()'

Quoting from es-python

# by default we connect to localhost:9200
es = Elasticsearch()
like image 28
Zouzias Avatar answered Oct 22 '22 21:10

Zouzias