windows环境下安装Python的Rtree包

python提供的一个第三方包Rtree包可以实现R树查询、删除、增添的各类操做。然而版主在windows环境 (win 10, python3.5)下安装Rtree包的时候出现了问题。直接在cmd中输入pip install Rtree后,会出现一下错误:html

Collecting Rtree
  Using cached Rtree-0.8.2.tar.gz
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "C:\Users\dellpc\AppData\Local\Temp\pip-build-zq00u5gn\Rtree\setup.py", line 4, in <module>
        import rtree
      File "C:\Users\dellpc\AppData\Local\Temp\pip-build-zq00u5gn\Rtree\rtree\__init__.py", line 1, in <module>
        from .index import Rtree
      File "C:\Users\dellpc\AppData\Local\Temp\pip-build-zq00u5gn\Rtree\rtree\index.py", line 6, in <module>
        from . import core
      File "C:\Users\dellpc\AppData\Local\Temp\pip-build-zq00u5gn\Rtree\rtree\core.py", line 101, in <module>
        raise OSError("could not find or load spatialindex_c.dll")
    OSError: could not find or load spatialindex_c.dllpython

如图所示:linux

 

固然,这个错误并非版主没有使用pip3致使的,错误提示是少了spatialindex_c.dll这个文件。因而版主顺藤摸瓜,发现Rtree包是基于libspatialindex开发的,在安装Rtree以前必须先安装libspatialindex。关于libspatialindex,除了官网的英文外,这里有一个中文翻译过来的介绍:http://blog.csdn.net/ljz2173/article/details/46009573,再也不多说。ios

因而版主又傻乎乎的去安装libspatialindex,可是开发这个libspatialindex的大神彷佛并不喜欢windows,官网上只给了十分简要的安装说明,不过基本等于没说呀,大概意思是本身去找个编译器编译后使用吧。。。版主又借助在海外的优点,四处google怎样在windows下安装libspatialindex,找了半天全是国外网友的疑问,却没人回答......看来大部分人都是用的Linux,版主这么小白还用windows简直就是错误......国内网友彷佛也无人问津这个问题。找了半天彷佛只有国外一个大神成功了,不过我按照他的步骤试了好久,仍是不行。这里仍是把地址贴出来,仅供参考:c++

http://lists.gispython.org/pipermail/spatialindex/2012-December/000336.html,有兴趣有时间的同窗能够一试睡觉git

其实!其实!其实!哪里会有那么多麻烦事...发现了另外一个Rtree官网的介绍,这里 http://toblerity.org/rtree/install.html#windows,看最下边win那里,“The Windows DLLs of libspatialindex are pre-compiled in windows installers that are available from PyPI. Installation on Windows is as easy as:” github

这明明就是说win版本的,这个Dll文件已经预编译进去了呀!!!根本不须要本身去装libspatialindex......windows

下边正式说安装步骤,废话有点多了:api

1. 这里 http://www.lfd.uci.edu/~gohlke/pythonlibs/#rtree 下载对应版本的Rtree的whl安装包,注意是python2.7仍是3.5,注意电脑是32仍是64位。能够放在电脑任意位置python2.7

2. 确保电脑里已经安装了python中wheel这个包,没有的话这个能够直接在cmd中输入pip install wheel安装

3. 打开cmd,输入pip install E:\软件安装包\Rtree-0.8.2-cp35-cp35m-win_amd64.whl,这个E盘是我存放Rtree的whl安装包的位置,本身安装的时候根据具体状况改一下便可。

而后两秒安装成功。

此时版主不知是该笑仍是该哭,只以为本身笨的要死...

不过,至今也没找到怎样正确在windows下安装libspatialindex的方法,还请大神指教。

顺便啰嗦一句吧,Linux安装libspatialindex的步骤大概以下:

https://github.com/libspatialindex/libspatialindex/wiki/1.-Getting-Started

鉴于国内github可能被墙,顺便也贴过来吧:

This tutorial will help you to get started with libspatialindex using C++ on linux. The following code is run on Ubuntu 12. If you are using windows the installation may be different. First install some prerequisites please enter the following into terminal. You may very well already have these installed.

sudo apt-get update sudo apt-get install curl sudo apt-get install g++ sudo apt-get install make

Now we download and install the library. It doesn't matter what directory you download this in. Please note the version number, you can check if there are more recent versions in the download page here http://download.osgeo.org/libspatialindex/ . Now enter the following into your terminal:

curl -L http://download.osgeo.org/libspatialindex/spatialindex-src-1.8.5.tar.gz | tar xz cd spatialindex-src-1.8.5 ./configure make sudo make install sudo ldconfig

libspatialindex should now be installed on your system. Let's try to make a small c++ program to test this. Create the file tutorial1.cpp somewhere and enter the following:

#include <iostream> #include <spatialindex/capi/sidx_api.h> using namespace std; using namespace SpatialIndex; int main(int argc, char* argv[]) { char* pszVersion = SIDX_Version(); fprintf(stdout, "libspatialindex version: %s\n", pszVersion); fflush(stdout); free(pszVersion); }

Now let's compile the code. Type the following into the console. Please note -std=c++0x makes it compile into C++11, although not required here it will be used in later examples.

g++ -std=c++0x tutorial1.cpp -lspatialindex_c -lspatialindex -o tutorial1

Now run the program:

./tutorial1

and it should output the following:

libspatialindex version: 1.8.5
相关文章
相关标签/搜索