1

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

karthikr
  • 97,368
  • 26
  • 197
  • 188
Marco Chiang
  • 159
  • 1
  • 4
  • 15

1 Answers1

3

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.

Ross
  • 17,861
  • 2
  • 55
  • 73
  • 3
    I disagree that this is a duplicate question; the 'dup' questions linked from here are all referring to the case where someone is trying to import bson from pymongo module; where in this case, the OP is trying to... correctly... import from bson module. I believe the correct solution to the problem is that one needs to REMOVE the standalone bson module, as it's overlapping with the pymongo installed bson module. eg, `pip uninstall bson` should do the trick. – calmrat Sep 30 '13 at 08:02