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?
That package is probably outdated or broken. Run
sudo apt-get purge python-pymongo
, thensudo apt-get install python-pip
, then finallysudo pip install pymongo
.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.
Python Script
Try it once, into python script run following statement
If above statement didn't throw any exception then you need to install
pymongo-2.4
, if existingpymongo
verion is2.3
Open terminal
First you need to uninstall old
pymongo
versionThen use following commands to install
pymongo-2.4