在我的django应用程序中导入pymongo时出错

时间:2013-04-11 03:26:39

标签: django mongodb pymongo

我正在尝试从django将文档插入到mongodb中,并且我在pymongo的import语句中收到错误。我没有任何名为pymongo的重复文件,我很确定我的virtualenv设置正确。

(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

2 个答案:

答案 0 :(得分:19)

pip install(在virtualenv中)pymongobson之后发生了此错误。

卸载pymongobson并再次安装pymongo - 它附带自己的bson版本与bson软件包不兼容。

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

答案 1 :(得分:0)

我已经解决了卸载 pymongo 的问题,并使用以下命令再次安装: python -m pip install pymongo