简体   繁体   中英

How do I fix “ImportError: No module named index” when importing RTree in Python?

I tried installing Rtree 0.7.0 from PyPI, but I keep getting ImportError: No module named index when I try to use it. I downloaded and ran the Rtree-0.7.0.win32.exe from the Downloads page, and everything appears to be installed properly.

Here's the full error message that I get (from the 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

The error message indicates that there's no module named 'index', but when I look in my C:\\Python32\\lib\\site-packages\\rtree\\ directory, I see that it's there.

RTree软件包目录

What could be causing me to still get the ImportError: No module named index error message, and how can I fix it so I can use the RTree module?

It appears to rely on import foo doing a relative import . It was the default behavior in 2.x (from 2.5 onwards there's a __future__ directive overriding that). Python 3 removed this . So the maintainers probably didn't even try to be 3.x-compatible, and the installation just worked by chance. Appropriately, there is no claim of Python 3 compatibility: No Programming Language :: Python :: 3 trove classifier, no mention in the documentation, no use of 2to3 in setup.py , etc. Short of patching rtree to fix this, and probably numerous other issues, you won't get it to work.

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