Reputation: 73
When I try to import Elasticsearch in python 3.5 to python 3.7 I get always the same Error.
from elasticsearch import Elasticsearch
print(Elasticsearch())
Traceback (most recent call last):
File "elasticsearch.py", line 3, in <module>
from elasticsearch import Elasticsearch
File "/app/elasticsearch.py", line 3, in <module>
from elasticsearch import Elasticsearch
ImportError: cannot import name 'Elasticsearch' from 'elasticsearch' (/app/elasticsearch.py)
Traceback (most recent call last):
File "elasticsearch.py", line 1, in <module>
from elasticsearch import Elasticsearch
File "/app/elasticsearch.py", line 1, in <module>
from elasticsearch import Elasticsearch
ImportError: cannot import name 'Elasticsearch' from partially initialized module 'elasticsearch' (most likely due to a circular import) (/app/elasticsearch.py)
I tried it with Ubuntu 18.04, Windows and Docker. For Docker I tried python:3.8 to python:3.5 also python:alpine-3.8 to python:alpine-3.5
elasticsearch==7.1.0
pip show elasticsearch
Name: elasticsearch
Version: 7.1.0
Summary: Python client for Elasticsearch
Home-page: https://github.com/elastic/elasticsearch-py
Author: Honza Král, Nick Lang
Author-email: [email protected], [email protected]
License: Apache License, Version 2.0
Location: /usr/local/lib/python3.7/site-packages
Requires: urllib3
Required-by:
PS
Also I tried to use elasticsearch version 6 & 5. But allways the same error. I'm quite confused...
Upvotes: 4
Views: 16767
Reputation: 6736
Your filename should not be as same as the package name. By renaming the file the problem would be solved. For more information why this error happened you can check this post.
Example:
elasticsearch.py ----rename-to----> sth-else.py
Upvotes: 5
Reputation: 2084
Like I said above just rename your script elasticsearch.py to another ..
Upvotes: 12