from elasticsearch import Elasticsearch
does not work.
import elasticsearch
e = elasticsearch.Elasticsearch(...)
does work.
I am trying to use a simple Elasticsearch client in python using AWS (ssh'd on an Amazon linux e3 machine). The code I am copying is here . I am unable to import the Elasticsearch class as described in the guide.
Using from elasticsearch import Elasticsearch
gives me the error: ImportError: cannot import name 'Elasticsearch'
.
I opened the python3 cli to check it out. If I type from elasticsearch import E
and tab-complete, I get the following suggestions: EOFError( Ellipsis EnvironmentError( Exception(
. However from elasticsearch import Ellipsis
gives me ImportError: cannot import name 'Ellipsis'
.
If I type import elasticsearch
, then on the next line elasticsearch.
and hit tab to autocomplete, I get the full range that I would expect ( Elasticsearch(
, RequestsHttpConnection(
, etc.).
I used pip3 install elasticsearch --user
to install it originally. I uninstalled it ( pip3 uninstall elasticsearch
) and returned to the python cli. from elasticsearch import E
still gives me EOFError( Ellipsis EnvironmentError( Exception(
on the tab-complete, but from elasticsearch import Ellipsis
now returns ModuleNotFoundError: No module named 'elasticsearch'
, as does just import elasticsearch
.
Not really quite sure what is up. I did not tag this as elasticsearch because it might be a user error :P
which python3
: /usr/bin/python3 which pip3
: ~/.local/bin/pip3 pip3 --version
: pip 18.1 from /home/ec2-user/.local/lib/python3.6/site-packages/pip (python 3.6) My problem was that I had named my file the same thing as the module I was trying to import from - elasticsearch.py
. As user2357112 states, I became hung up on the incorrect autocomplete.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.