Reputation: 345
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
Reputation: 1
go to Command prompt.
Upvotes: 0
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
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
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