简体   繁体   中英

python - Import breaks, because library cannot import its own modules

I'm trying to use mongokit in my Pyramid project, but when I import it, I get the following error.

  File "foo.py", line 5, in <module>
    import mongokit
  File "/home/.../mongokit/__init__.py", line 33, in <module>
    from cursor import Cursor
ImportError: No module named 'cursor'

There is a cursor.py file with a Cursor class in it in the same folder as __init__.py .

According to the documentation , when you import a module, it is supposed to put its own directory at the beginning of the search path. However, when I print out sys.path from both foo.py and __init__.py , it is the same in both places.

I can't find anyone else having this problem.

Edit: I am using Python 3.3

mongokit is not compatible with python 3.

From their version notes:

v0.9.0 now MongoKit requires PyMongo >= 2.5

如果您使用python 3.x并尝试为python 2.x导入某些模块,则可能会发生相同的错误。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM