4

When I try to import Elasticsearch in python 3.5 to python 3.7 I get always the same Error.

Code:

from elasticsearch import Elasticsearch
print(Elasticsearch())

Error:

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)

The Error for Python 3.8

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

As requirements I use:

elasticsearch==7.1.0

Searching for Elasticseach Package

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...

2
  • 5
    I think your script name is elasticsearch.py ???...change the name file Commented Dec 19, 2019 at 15:52
  • 1
    Damn yeah this was my problem 🤦‍♂ now it works, thanks Commented Dec 19, 2019 at 15:55

2 Answers 2

12

Like I said above just rename your script elasticsearch.py to another ..

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

Comments

5

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

Comments

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.