Python Question

Can't import MongoClient

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
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?

Answer Source

That package is probably outdated or broken. Run sudo apt-get purge python-pymongo, then sudo apt-get install python-pip, then finally sudo pip install pymongo.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download