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
相關文章
相關標籤/搜索