我正在完全遵循本教程。尝试使用virtualenv多次删除和重新启动,我仍然遇到错误。是蟒蛇,mongodb和django应该是这个令人沮丧的设置?
http://docs.mongodb.org/manual/tutorial/write-a-tumblelog-application-with-django-mongodb-engine/
我试图打电话时遇到问题
post.save()
然后我收到此错误:
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**
请有人带领我朝着正确的方向前进。是否有更好的教程可以遵循,因为我遵循的每个教程都会遇到错误。我即将放弃pymongo和django ......
答案 0 :(得分:3)
看起来环境设置不正确。你能确保你的python shell中有pymongo可用:
$> python.exe
然后在shell中:
>>> import pymongo
>>> pymongo.version
该报告的版本是什么?
还尝试导入bson:
>>> import bson
如果这些工作,那么请确保您在同一环境中运行django mongodb-engine应用程序。