Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
167 views
in Technique[技术] by (71.8m points)

python - ImportError: No module named objectid

I have currently django-mongodb-engine 0.4.0 version installed on my Mac OS X 10.6.8 and weirdly encountered an interesting error while importing the 'compiler' module:

>> from django_mongodb_engine import compiler

and I got the following error:

ImportError Traceback (most recent call last)
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django_extensions/management/commands/shell_plus.pyc in <module>()
----> 1 from django_mongodb_engine import compiler

/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django_mongodb_engine/compiler.pyc in <module>()
      15 from pymongo.errors import PyMongoError
      16 from pymongo import ASCENDING, DESCENDING
 ---> 17 from pymongo.objectid import ObjectId, InvalidId
      18 
      19 from djangotoolbox.db.basecompiler import NonrelQuery, NonrelCompiler, 

ImportError: No module named objectid

I installed the package via pip command and all the dependencies like pymongo, djangotoolbox have been installed along with it. The pip command I'd used is this:

>> sudo env ARCHFLAGS='-arch i386 -arch x86_64' pip install --upgrade  django-mongodb-engine

The current versions of the related packages are:

>> pip freeze | grep mongo
django-mongodb-engine==0.4.0
pymongo==2.2

I suspect the django_mongodb_engine package is broken because ObjectId is not imported inside pymongo anymore. Instead, it belongs to bson module.

What are your suggestions to fix this problem? Should I clone the django-mongodb-engine project and fix on github?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I've ran into something similar, for me the problem was this line:

from pymongo.objectid import ObjectId

The call seems to work in versions of PyMongo < 2.2

In pymongo 2.2 the call to import objectid is:

from bson.objectid import ObjectId

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...