python - MongoKit "ImportError: No module named objectid "错误

标签 python python-2.7 flask pymongo mongokit

我在使用 MongoKit 时遇到一些非常奇怪的错误:

>>> from mongokit import *
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/mongokit/__init__.py", line 35, in <module>
    from document import Document, ObjectId
  File "/usr/local/lib/python2.7/dist-packages/mongokit/document.py", line 48, in <module>
    from pymongo.objectid import ObjectId
ImportError: No module named objectid

我想尽一切办法找出原因,但无济于事。 实际上,我在谷歌上搜索了“ImportError:没有名为 objectid 的模块”错误,但根本没有结果。我尝试按照简单教程 http://namlook.github.com/mongokit/introduction.html#a-quick-example 使用 MongoKit本教程的第一行产生了这个奇怪的错误。下面是MongoKit安装日志。

我做错了什么?

user@server:~$ sudo pip install mongokit
Downloading/unpacking mongokit
  Downloading mongokit-0.7.2.tar.gz (69Kb): 69Kb downloaded
  Running setup.py egg_info for package mongokit

Downloading/unpacking pymongo>=2.0.1 (from mongokit)
  Downloading pymongo-2.2.tar.gz (228Kb): 228Kb downloaded
  Running setup.py egg_info for package pymongo

Downloading/unpacking anyjson>=0.2.2 (from mongokit)
  Downloading anyjson-0.3.1.tar.gz
  Running setup.py egg_info for package anyjson

Installing collected packages: mongokit, pymongo, anyjson
  Running setup.py install for mongokit

  Running setup.py install for pymongo
    building 'bson._cbson' extension
    gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -Ibson -I/usr/include/python2.7 -c bson/_cbsonmodule.c -o build/temp.linux-i686-2.7/bson/_cbsonmodule.o
    gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -Ibson -I/usr/include/python2.7 -c bson/time64.c -o build/temp.linux-i686-2.7/bson/time64.o
    gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -Ibson -I/usr/include/python2.7 -c bson/buffer.c -o build/temp.linux-i686-2.7/bson/buffer.o
    gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -Ibson -I/usr/include/python2.7 -c bson/encoding_helpers.c -o build/temp.linux-i686-2.7/bson/encoding_helpers.o
    gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-Bsymbolic-functions -Wl,-z,relro build/temp.linux-i686-2.7/bson/_cbsonmodule.o build/temp.linux-i686-2.7/bson/time64.o build/temp.linux-i686-2.7/bson/buffer.o build/temp.linux-i686-2.7/bson/encoding_helpers.o -o build/lib.linux-i686-2.7/bson/_cbson.so
    building 'pymongo._cmessage' extension
    gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -Ibson -I/usr/include/python2.7 -c pymongo/_cmessagemodule.c -o build/temp.linux-i686-2.7/pymongo/_cmessagemodule.o
    gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -Ibson -I/usr/include/python2.7 -c bson/buffer.c -o build/temp.linux-i686-2.7/bson/buffer.o
    gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-Bsymbolic-functions -Wl,-z,relro build/temp.linux-i686-2.7/pymongo/_cmessagemodule.o build/temp.linux-i686-2.7/bson/buffer.o -o build/lib.linux-i686-2.7/pymongo/_cmessage.so

  Running setup.py install for anyjson

Successfully installed mongokit pymongo anyjson
Cleaning up...

最佳答案

这是依赖项中的错误。截至PyMongo 1.11 objectid lives in the bson module, not pymongo .

关于python - MongoKit "ImportError: No module named objectid "错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10401499/

相关文章:

python - 类 lambda 回调 NameError

python - 如何在 tensorflow 中将字典转换为张量

python - 根据 GMT(伦敦)夏令时检测和更改时间增量?

python - 在pygame中创建一个圆周上有点的圆

python - 有条件地应用 Flask-HTTPAuth 的 login_required 装饰器

python - 在 Flask 中,有没有办法对应用程序本身以外的所有人隐藏 @app.route。我的数据库可以从 JSON 格式的 url 中看到

Raspberry Pi 上的 Python 脚本在执行 mysql 语句时出现错误

python - QlistWidget 图标 - 加载速度更快

python需要帮助来提取模式

python - 使用 Flask 流式传输生成的 CSV