问题
I'm following this tutorial exactly. Tried deleting and restarting many times with virtualenv and I'm still getting errors. Is it python, mongodb and django supposed to be this frustrating to set up?
http://docs.mongodb.org/manual/tutorial/write-a-tumblelog-application-with-django-mongodb-engine/
I get a problem when I try to call
post.save()
I then get this error:
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/db/models/base.py", line 460, in save
self.save_base(using=using, force_insert=force_insert, force_update=force_update)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/db/models/base.py", line 553, in save_base
result = manager._insert(values, return_id=update_pk, using=using)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/db/models/manager.py", line 195, in _insert
return insert_query(self.model, values, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/db/models/query.py", line 1436, in insert_query
return query.get_compiler(using=using).execute_sql(return_id)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/db/models/sql/query.py", line 213, in get_compiler
return connection.ops.compiler(self.compiler)(self, connection, using)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/db/backends/__init__.py", line 576, in compiler
self._cache = import_module(self.compiler_module)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/Users/marcochiang/Desktop/Development/caesarWorkflow/lib/python2.7/site-packages/django_mongodb_engine/compiler.py", line 18, in <module>
from bson.objectid import ObjectId
**ImportError: No module named bson.objectid**
Please someone lead me in the right direction. Is there a better tutorial to follow because every single tutorial I follow I run into errors. I'm about to give up on pymongo and django...
回答1:
It looks like the environment isn't setup correctly. Can you ensure that pymongo is available in your python shell:
$> python.exe
Then in the shell:
>>> import pymongo
>>> pymongo.version
What version does that report?
Also try importing bson:
>>> import bson
If those work then make sure you are running your django mongodb-engine app in the same environment.
来源:https://stackoverflow.com/questions/17266010/python-django-mongodb-importerror-no-module-named-bson-objectid