Can't import MongoClient

后端 未结 11 986
时光取名叫无心
时光取名叫无心 2021-01-01 21:18

I am unable to do this:

from pymongo import MongoClient

I get:

>>> import pymongo
>>> from pymongo import         


        
相关标签:
11条回答
  • 2021-01-01 21:45

    If you used pymongo.Connection and encountered error, you should know that after the new updates, you should use pymongo.MongoClient instead. I had this issue so hopefully this will be helpful to someone else.

    0 讨论(0)
  • 2021-01-01 21:45

    Make sure your python source file is not called pymongo.py

    0 讨论(0)
  • 2021-01-01 21:53

    This problem may occur if you have multiple .py programs in the current working directory. Deleting them solved my error. I am not sure of the reason though.

    0 讨论(0)
  • 2021-01-01 21:59

    According to docs, MongoClient was introduced in version 2.4. As you installed pymongo from your distribution repository, it's quite possible it's not the most recent version. Try installing it via PiP (remove the one you have installed first):

    pip install pymongo
    
    0 讨论(0)
  • 2021-01-01 21:59

    Worked for me for conda env

    pip uninstall pymongo
    

    then

    pip install pymongo
    
    0 讨论(0)
  • 2021-01-01 22:00

    If you had named your script pymongo.py, which masks the pymongo module from which you are importing.

    Rename your script to something else like xyz.py (and delete the pymongo.pyc file if one was created next to it).

    0 讨论(0)
提交回复
热议问题