PyMongo and ImportError

1,853 views
Skip to first unread message

Philip Southam [movieclips.com]

unread,
Sep 20, 2010, 7:16:46 PM9/20/10
to mongodb-user
Is anyone else using the pymongo driver getting this error (while
trying to import pymongo) on git checkouts dated after Thu Sep 9
11:47:52 2010 -0400?

Traceback (most recent call last):
File "<string>", line 1, in <module>
File "pymongo/__init__.py", line 17, in <module>
from pymongo.connection import Connection as PyMongo_Connection
File "pymongo/connection.py", line 45, in <module>
from pymongo import (database,
File "pymongo/database.py", line 19, in <module>
from bson.code import Code
File "pymongo/bson.py", line 24, in <module>
File "pymongo/binary.py", line 15, in <module>
from bson.binary import *
ImportError: No module named binary


Commit 021136e797d1992e6e1734d634cb2d8ac1ee8ce5 works fine, anything
after that I get the above error. Duplicated on both my Mac and Linux
environments on the latest python 2.6 release.

Michael Dirolf

unread,
Sep 21, 2010, 10:18:42 AM9/21/10
to mongod...@googlegroups.com
Is it possible that you have some old pyc files around or something?
The file pymongo/bson.py was removed in the commit that you mention,
and the problem seems to be that that module is still getting picked
up instead of the new bson package.

> --
> You received this message because you are subscribed to the Google Groups "mongodb-user" group.
> To post to this group, send email to mongod...@googlegroups.com.
> To unsubscribe from this group, send email to mongodb-user...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/mongodb-user?hl=en.
>
>

Michael Dirolf

unread,
Sep 21, 2010, 2:06:45 PM9/21/10
to mongod...@googlegroups.com
Just debugged w/ somebody else who was having the same issue and it
seems like my suspicion might have been correct. Make sure to clean
out your src checkout of any build artifacts and then try
reinstalling.

Philip Southam [movieclips.com]

unread,
Sep 22, 2010, 12:37:56 PM9/22/10
to mongodb-user
Michael,

Thanks for the suggestion. I didn't get a chance to update my post
yesterday; but yes, I removed the existing pymongo directory and
rechecked it out. Doing so seemed to resolve the issue. Strange that
doing the python setup.py clean before installing didn't remove the
old files properly...

Regards,
Philip

brad103

unread,
Sep 28, 2010, 7:39:18 PM9/28/10
to mongodb-user
I'm having a similar problem on Windows using Buildout. I have deletd
the orginal pymongo directory and retried.

import pymongo
File "D:\dev\eggs\pymongo-1.9-py2.6-win32.egg\pymongo\__init__.py",
line 17, in <module>
from pymongo.connection import Connection as PyMongo_Connection
File "D:\dev\eggs\pymongo-1.9-py2.6-win32.egg\pymongo
\connection.py", line 45, in <module>
from pymongo import (database,
File "D:\dev\eggs\pymongo-1.9-py2.6-win32.egg\pymongo\database.py",
line 19, in <module>
from bson.code import Code
File "D:\dev\eggs\pymongo-1.9-py2.6-win32.egg\pymongo\bson.py", line
24, in <module>
from pymongo.binary import Binary
File "D:\dev\eggs\pymongo-1.9-py2.6-win32.egg\pymongo\binary.py",
line 15, in <module>
from bson.binary import *
ImportError: No module named binary

You'll see a couple of differences from Philip's traceback, presumably
platform-related differences.

If I modify pymongo/binary.py and add:

print help(bson)

I get:

Help on module pymongo.bson in pymongo:

NAME
pymongo.bson - Tools for dealing with Mongo's BSON data
representation.

FILE
d:\dev\eggs\pymongo-1.9-py2.6-win32.egg\pymongo\bson.py

DESCRIPTION
Generally not needed to be used by application developers.

None


So it seems that the import from bson.binary would be looking for
pymongo.bson.binary, correct??

Thanks
Brad


On Sep 23, 5:37 am, "Philip Southam [movieclips.com]"

Spaggh

unread,
Sep 29, 2010, 4:30:21 AM9/29/10
to mongodb-user
Must delete the files .. \ pymongo \ BSON .*
If you look here: http://github.com/mongodb/mongo-python-driver/tree/master/pymongo/
BSON .* files have disappeared.

It works. =)

Markus Gattol

unread,
Sep 29, 2010, 6:24:06 AM9/29/10
to mongod...@googlegroups.com
Note that, as generally true for all drivers, BSON (Binary JSON) has
become its own package within the PyMongo distribution.
http://api.mongodb.org/python/1.9%2B/changelog.html

The rationale being that BSON is a language independent data interchange
format, thus should not be exclusive to MongoDB. Having a distinct
Python package helps with this as other open source projects might be
more willing to use it.

Michael Dirolf

unread,
Sep 29, 2010, 9:31:16 AM9/29/10
to mongod...@googlegroups.com
I think there might have been a slip-up when packaging the windows
binaries for the 1.9 release. I will try to repackage them and let you
know when you should give it another shot.

Michael Dirolf

unread,
Sep 29, 2010, 9:44:55 AM9/29/10
to mongod...@googlegroups.com
I've repackaged the windows binaries - could you retry again please,
and let us know how it goes?

brad103

unread,
Sep 29, 2010, 8:01:23 PM9/29/10
to mongodb-user
Works fine now. Thanks Michael

On Sep 30, 2:44 am, Michael Dirolf <m...@10gen.com> wrote:
> I've repackaged the windows binaries - could you retry again please,
> and let us know how it goes?
>
> On Wed, Sep 29, 2010 at 09:31, Michael Dirolf <m...@10gen.com> wrote:
> > I think there might have been a slip-up when packaging the windows
> > binaries for the 1.9 release. I will try to repackage them and let you
> > know when you should give it another shot.
>

Michael Dirolf

unread,
Sep 29, 2010, 9:46:40 PM9/29/10
to mongod...@googlegroups.com
Great - thanks!
Reply all
Reply to author
Forward
0 new messages