本文介绍了MongoKit“ImportError:No module named objectid”错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 >>>使用MongoKit时出现一些非常奇怪的错误: from mongokit import * 
Traceback(最近一次调用的最后一个):
在< module>中的第1行中输入< stdin>
文件/usr/local/lib/python2.7/dist-packages/mongokit/__init__.py,第35行,在< module>
从文档导入Document,ObjectId
文件/usr/local/lib/python2.7/dist-packages/mongokit/document.py,第48行,在< module>
from pymongo.objectid import ObjectId
ImportError:没有模块名为objectid

I试图找到原因,但没有任何帮助。
其实我googledImportError:没有名为objectid模块错误,它根本没有结果。我尝试使用简单教程,本教程的第一行产生了这个奇怪的错误。下面是MongoKit安装的日志。



我在做什么错?

  user @ server:〜$ sudo pip install mongokit 
下载/解包mongokit
正在下载mongokit-0.7.2.tar.gz(69Kb):69Kb已下载
正在运行setup.py egg_info for package mongokit

下载/解包pymongo> = 2.0.1(来自mongokit)
正在下载pymongo-2.2.tar.gz(228Kb):228Kb已下载
正在运行的设置。 py egg_info for package pymongo

下载/解包anyjson> = 0.2.2(from mongokit)
下载anyjson-0.3.1.tar.gz
运行setup.py egg_info包anyjson

安装收集的软件包:mongokit,pymongo,anyjson
运行setup.py安装mongokit

运行setup.py安装pymongo
building 'bson._cbson'扩展
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'p ymongo._cmessage'扩展
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-W1,-Bsymbolic-functions-W1,-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

运行setup.py安装anyjson

成功安装mongokit pymongo anyjson
清理up ...


解决方案

这是依赖关系中的错误。从 。


I get some very strange error using 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

I tried everything to find the reason but nothing helps.Actually I googled "ImportError: No module named objectid" error and it has no results at all. I tried to use MongoKit following the simple tutorial http://namlook.github.com/mongokit/introduction.html#a-quick-example and the first line of the tutorial produces this strange error. Below is the log of MongoKit installation.

What I'm doing wrong?

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...
解决方案

It's an error in the dependencies. As of PyMongo 1.11 objectid lives in the bson module, not pymongo.

这篇关于MongoKit“ImportError:No module named objectid”错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-04 23:58