ImportError: cannot import name MongoClient

1,331 views
Skip to first unread message

Yaroslav Kyrpych

unread,
Apr 4, 2014, 1:59:24 PM4/4/14
to mongod...@googlegroups.com
Hi,

I am trying to run pymongo in Python, and getting the following error when Python code tries to execute: ImportError: cannot import name MongoClient.

I have mognod running. Here's relevant part of code:

import pymongo
from pymongo import MongoClient

client=MongoClient()
db=client.test_db
collection=db.test_collection

Any suggestions? Do I need to specify path to mongodb location?

Thank you,

Yaroslav

Bernie Hackett

unread,
Apr 4, 2014, 2:44:42 PM4/4/14
to mongod...@googlegroups.com
What version of PyMongo are you using? MongoClient was added in 2.4.


--
You received this message because you are subscribed to the Google Groups "mongodb-user"
group.
 
For other MongoDB technical support options, see: http://www.mongodb.org/about/support/.
---
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user...@googlegroups.com.
To post to this group, send email to mongod...@googlegroups.com.
Visit this group at http://groups.google.com/group/mongodb-user.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/CABSeBizuEOngQOmKX%3DhhO%2BSftHhGnKXdArmWY2HaeKmTmg2WwA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Yaroslav Kyrpych

unread,
Apr 4, 2014, 3:44:44 PM4/4/14
to mongod...@googlegroups.com

Bernie Hackett

unread,
Apr 4, 2014, 4:05:42 PM4/4/14
to mongod...@googlegroups.com
That's the version of python you are using. I'm looking for the pymongo version. Do this and post the result:

python -c "import pymongo; print pymongo.version"


Yaroslav Kyrpych

unread,
Apr 4, 2014, 4:22:12 PM4/4/14
to mongod...@googlegroups.com, mongod...@googlegroups.com
I am using python 3.3, mongodb is 2.4.6. On Win 7.

Bernie Hackett

unread,
Apr 4, 2014, 4:33:48 PM4/4/14
to mongod...@googlegroups.com
Great. I still need to know what version of PyMongo you are using.

C:\Python33\python.exe -c "import pymongo; print pymongo.version"


Bernie Hackett

unread,
Apr 4, 2014, 4:37:22 PM4/4/14
to mongod...@googlegroups.com
Sorry, since you are using python 3.3:

C:\Python33\python.exe -c "import pymongo; print(pymongo.version)"

Bernie Hackett

unread,
Apr 4, 2014, 4:51:40 PM4/4/14
to mongod...@googlegroups.com
Here's an example powershell session:

Windows PowerShell
Copyright (C) 2009 Microsoft Corporation. All rights reserved.

PS C:\Users\Administrator> C:\Python33\python.exe -m easy_install pymongo
Searching for pymongo
Best match: pymongo 2.7
Processing pymongo-2.7-py3.3-win-amd64.egg
creating c:\python33\lib\site-packages\pymongo-2.7-py3.3-win-amd64.egg
Extracting pymongo-2.7-py3.3-win-amd64.egg to c:\python33\lib\site-packages
Adding pymongo 2.7 to easy-install.pth file

Installed c:\python33\lib\site-packages\pymongo-2.7-py3.3-win-amd64.egg
Processing dependencies for pymongo
Finished processing dependencies for pymongo
PS C:\Users\Administrator> C:\Python33\python.exe -c "import pymongo; print(pymongo.version)"
2.7
PS C:\Users\Administrator> C:\Python33\python.exe
Python 3.3.5 (v3.3.5:62cf4e77f785, Mar  9 2014, 10:35:05) [MSC v.1600 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from pymongo import MongoClient
>>> import pymongo
>>> pymongo.has_c()
True
>>>

Yaroslav Kyrpych

unread,
Apr 4, 2014, 5:11:53 PM4/4/14
to mongod...@googlegroups.com, mongod...@googlegroups.com
Tried to run as suggested. Strangely, I am getting error - module object has no attribute 'version'.
Reply all
Reply to author
Forward
0 new messages