2012-05-01 24 views
7

me sale un error muy extraño usando MongoKit:MongoKit "ImportError: Sin módulo denominado objectid" error

>>> 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 

que intentó todo para encontrar la razón, pero nada ayuda. Realmente busqué en Google el error "ImportError: No module named objectid" y no tiene ningún resultado. Traté de usar MongoKit siguiendo el sencillo tutorial http://namlook.github.com/mongokit/introduction.html#a-quick-example y la primera línea del tutorial produce este extraño error. A continuación se muestra el registro de la instalación de MongoKit.

¿Qué estoy haciendo mal?

[email protected]:~$ 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... 

Respuesta

11

Es un error de las dependencias. A partir del PyMongo 1.11objectid lives in the bson module, not pymongo.

+0

¿Hay alguna forma de solucionarlo? ¿O debería volver a escribir el código fuente de un tercero? Es algo muy básico, en realidad la primera línea del tutorial y no funciona. 'Coz todo lo que estoy haciendo - simplemente importar 'de importación mongokit *' – Zelid

+0

Es un informe de error: https://github.com/namlook/mongokit/pull/88 – Electro

+0

gracias, voy a tratar de pepita instalar la versión reciente de git – Zelid

10

Como dijo Electro, es un error.

que utilizó la siguiente pequeño truco sucio para mantener mi sitio en funcionamiento hasta que se fija:

import sys 
import pymongo 
import bson.objectid 
pymongo.objectid = bson.objectid 
sys.modules["pymongo.objectid"] = bson.objectid 
Cuestiones relacionadas