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()


It tells me the following:

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

ImportError: No module named elasticsearch

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

Best answer

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.