7

I just installed with pip install elasticsearch the right package, but is not being found by my .py script.

I have this right now:

ls /Library/Python/2.7/site-packages

README                       pip-1.5.6-py2.7.egg          urllib3-1.8.3-py2.7.egg-info virtualenv.py                virtualenv_support
easy-install.pth             urllib3                      virtualenv-1.11.6.dist-info  virtualenv.pyc

ls /usr/local/lib/python2.7/site-packages/

easy-install.pth              elasticsearch-1.0.0.dist-info setuptools-4.0.1-py2.7.egg    sitecustomize.py
elasticsearch                 pip-1.5.6-py2.7.egg           setuptools.pth                sitecustomize.pyc

Now when I run my script myelastic.py:

import sys
print sys.path

from elasticsearch import Elasticsearch
es = Elasticsearch()

I have this:

['/Users/tati/Desktop/python', '/Applications/MAMP/Library/lib/python27.zip', '/Applications/MAMP/Library/lib/python2.7', '/Applications/MAMP/Library/lib/python2.7/plat-darwin', '/Applications/MAMP/Library/lib/python2.7/plat-mac', '/Applications/MAMP/Library/lib/python2.7/plat-mac/lib-scriptpackages', '/Applications/MAMP/Library/lib/python2.7/lib-tk', '/Applications/MAMP/Library/lib/python2.7/lib-old', '/Applications/MAMP/Library/lib/python2.7/lib-dynload', '/Applications/MAMP/Library/lib/python2.7/site-packages']
Traceback (most recent call last):
  File "myelastic.py", line 5, in <module>
    from elasticsearch import Elasticsearch
ImportError: No module named elasticsearch

It's the first time I work with virtualenv, but I'm not sure how to work around this issue, thanks!

1
  • you mention virtualenv but I can't see a trace of it. Commented Jun 29, 2014 at 17:57

2 Answers 2

15

You have called your file the same name as the module:

File "/Users/tati/Desktop/python/elasticsearch.py".

It is shadowing the module name so you are importing from your file not the elasticsearch module. Just rename your .py to something other than elasticsearch.py.

Sign up to request clarification or add additional context in comments.

9 Comments

I just renamed it, was part of the problem, thanks!, but still the rest, is not finding the library, but thanks!
are you trying to import from a venv or using the system python?
mmmmmmm I ran "virtualenv <folder project>", that is using the venv no?
did you install using pip after you activated your venv?
*pip install virtualenv *pip install elasticsearch
|
1

I had the same issue. I fixed it by adding to my .bash_profile :

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

3 Comments

This is Mac OS X specific.
Yes I was testing on mac but still. I had the issue and it is how I fixed. People, as I did, may be googling the issue and find my point interesting.
On Ubuntu it's /usr/local/lib/python2.7/site-packages

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.