I am unable to do this:
from pymongo import MongoClient
I get:
>>> import pymongo
>>> from pymongo import MongoClient
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: cannot import name MongoClient
>>>
I am able to import pymongo
without issues.
I am running mongodb 2.2.3
and Python 2.7
.
I've also tried this:
>>> connection = pymongo.MongoClient()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'MongoClient'
>>>
What am I doing wrong?
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).
yes it's true you need to update use, check the upgrade section says http://api.mongodb.org/python/current/installation.html
I had the same problem on Ubuntu 16.04.
This solved my problem:
According to docs,
MongoClient
was introduced in version 2.4. As you installedpymongo
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):I would like to suggest more robust answer:
now see where it direct you and from there simply remove the pymongo directory
Now, you can safely install pymongo again:
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.