Python does not find elasticsearch package

I just installed the correct package with pip install elasticsearch but did not find its .py script.

I have it 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 it:

['/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

This is the first time I work with virtualenv, but I'm not sure how to get around this problem, thanks!

+4
source share
2 answers

You named your file the same name as the module:

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

It obscures the module name, so you are not importing an elasticsearch module from your file. Just rename yours .pyto something else elasticsearch.py.

+9

. , .bash_profile:

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

Source: https://habr.com/ru/post/1546490/


All Articles