Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error importing pymongo in my django app

I'm trying to insert documents into mongodb from django and I'm getting an error on the import statement for pymongo. I don't have a duplicate file anywhere called pymongo and I'm pretty sure my virtualenv is set up correctly.

(django-sample-app)ubuntu@django (884) ~ $ python

Python 2.7.3 (default, Aug  1 2012, 05:14:39) 

[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.

>>> import bson

>>> import pymongo

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/ubuntu/.virtualenvs/django-sample-app/local/lib/python2.7/site-packages/pymongo/__init__.py", line 80, in <module>
    from pymongo.connection import Connection
  File "/home/ubuntu/.virtualenvs/django-sample-app/local/lib/python2.7/site-packages/pymongo/connection.py", line 39, in <module>
    from pymongo.mongo_client import MongoClient
  File "/home/ubuntu/.virtualenvs/django-sample-app/local/lib/python2.7/site-packages/pymongo/mongo_client.py", line 45, in <module>
    from pymongo import (auth,
  File "/home/ubuntu/.virtualenvs/django-sample-app/local/lib/python2.7/site-packages/pymongo/database.py", line 22, in <module>
    from pymongo.collection import Collection
  File "/home/ubuntu/.virtualenvs/django-sample-app/local/lib/python2.7/site-packages/pymongo/collection.py", line 25, in <module>
    from pymongo.cursor import Cursor
  File "/home/ubuntu/.virtualenvs/django-sample-app/local/lib/python2.7/site-packages/pymongo/cursor.py", line 19, in <module>
    from bson import RE_TYPE
ImportError: cannot import name RE_TYPE
like image 323
kelorek Avatar asked Apr 11 '13 03:04

kelorek


1 Answers

This error happened to me after pip install (in virtualenv) both pymongo and bson.

Uninstall pymongo and bson and install again just pymongo - it ships with its own version of bson not compatible with the bson package.

https://stackoverflow.com/a/12983651/196206

like image 150
Messa Avatar answered Oct 16 '22 14:10

Messa