9

我正在尝试从 django 将文档插入 mongodb,但在 pymongo 的导入语句中出现错误。我在任何地方都没有名为 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
4

2 回答 2

19

pip install(在 virtualenv 中)pymongobson.

卸载pymongobson重新安装只是-它附带了与该软件包不兼容pymongo的自己的版本。bsonbson

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

于 2014-08-19T12:17:21.640 回答
0

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

于 2021-08-06T16:56:29.717 回答