Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error while importing MongoClient from pymongo module [duplicate]

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()
like image 786
Iqbal honnur Avatar asked Feb 02 '26 22:02

Iqbal honnur


1 Answers

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.

like image 59
Vishal Kamlapure Avatar answered Feb 05 '26 11:02

Vishal Kamlapure



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!