Jorge
Jorge

Reputation: 345

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?

Upvotes: 20

Views: 45217

Answers (5)

Nikhil Annadanam
Nikhil Annadanam

Reputation: 1

go to Command prompt.

  1. python -m pip install elasticsearch (use python -m )
  2. python
  3. import elasticsearch

Upvotes: 0

fiberair
fiberair

Reputation: 651

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.

Upvotes: 7

Bruno Gallien
Bruno Gallien

Reputation: 19

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

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

Upvotes: 0

abhishektalluri
abhishektalluri

Reputation: 391

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.

Upvotes: 3

Zouzias
Zouzias

Reputation: 2360

You should capitalize the 'elasticsearch()'

Quoting from es-python

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

Upvotes: 4

Related Questions