2

I am trying to import MongoClient class from the pymongo module and getting the below error

Traceback (most recent call last):
  File "pymongo.py", line 3, in <module>
    import pymongo
  File "C:\Users\Iqbal\Desktop\pymongo.py", line 5, in <module>
    client = pymongo.MongoClient()
AttributeError: partially initialized module 'pymongo' has no attribute 'MongoClient' (most likely due to a circular import)

I have installed latest version of pymongo, which is 3.10.1

import requests
import pymongo

client = pymongo.MongoClient()
1
  • What other messages are there? Commented May 27, 2020 at 15:51

1 Answer 1

10

I think you named your file same as module name i.e, pymongo.py. Change it to something else and that should work for you.

Also delete the pymongo.pyc file if one was created next to it.

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

3 Comments

Yes, my file name was pymongo.py and I renamed it now. Thanks :-)
My project name was "pymongo" i changed..and it worked
My file name was also 'pymongo' and it works as you guide. Thanks.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.