python - 在Python中导入RTree时如何修复 "ImportError: No module named index"?

标签 python python-3.x r-tree

我尝试安装Rtree 0.7.0来自 PyPI,但当我尝试使用它时,我不断收到 ImportError: No module named index 。我从 Downloads 下载并运行 Rtree-0.7.0.win32.exe页面,一切似乎都已正确安装。

这是我收到的完整错误消息(来自 Python 3.2.2 shell):

>>> from rtree import index
Traceback (most recent call last):
  File "<pyshell#0>", line 1, in <module>
    from rtree import index
  File "C:\Python32\lib\site-packages\rtree\__init__.py", line 1, in <module>
    from index import Rtree
ImportError: No module named index

>>> import rtree
Traceback (most recent call last):
  File "<pyshell#1>", line 1, in <module>
    import rtree
  File "C:\Python32\lib\site-packages\rtree\__init__.py", line 1, in <module>
    from index import Rtree
ImportError: No module named index

错误消息表明没有名为“index”的模块,但是当我查看我的 C:\Python32\lib\site-packages\rtree\ 目录时,我发现它就在那里。

RTree Package Directory

什么可能导致我仍然收到 ImportError: No module named index 错误消息,如何修复它以便我可以使用 RTree 模块?

最佳答案

它似乎依赖于 import foo 执行 relative import 。这是 2.x 中的默认行为(从 2.5 开始,有一个 __future__ 指令覆盖了它)。 Python 3 removed this 。因此,维护人员可能甚至没有尝试兼容 3.x,安装只是偶然。适本地,没有声称 Python 3 兼容性:没有 Programming Language::Python::3 trove 分类器,文档中没有提及,在 setup.py 中没有使用 2to3 > 等。如果不修补 rtree 来解决此问题,以及可能存在的许多其他问题,您将无法使其正常工作。

关于python - 在Python中导入RTree时如何修复 "ImportError: No module named index"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14084383/

相关文章:

python - 如果 DoubleVar 或 IntVar 为空,tkinter python 3.4 设置为零

python - 在 Python 中搜索列表中的元素

python - python中有序集合的交集

python - 使用标签作为 pandas 数据帧的标题来旋转 Pandas 中的 XML 数据

python - 属性错误 : type object 'Image' has no attribute 'open'

python : correct use of set_completion_display_matches_hook

python - 理解 *x ,= lst

c++ - 如何迭代boost R-tree?

c# - 持久(基于磁盘)R 树(或 R* 树)

python - 序列化和反序列化以及 Python RTree