windows環境下安裝Python的Rtree包


python提供的一個第三方包Rtree包能夠實現R樹查詢、刪除、增添的各種操作。然而版主在windows環境 (win 10, python3.5)下安裝Rtree包的時候出現了問題。直接在cmd中輸入pip install Rtree后,會出現一下錯誤:

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.dll

如圖所示:

 

當然,這個錯誤並不是版主沒有使用pip3導致的,錯誤提示是少了spatialindex_c.dll這個文件。於是版主順藤摸瓜,發現Rtree包是基於libspatialindex開發的,在安裝Rtree之前必須先安裝libspatialindex。關於libspatialindex,除了官網的英文外,這里有一個中文翻譯過來的介紹:http://blog.csdn.net/ljz2173/article/details/46009573,不再多說。

於是版主又傻乎乎的去安裝libspatialindex,但是開發這個libspatialindex的大神似乎並不喜歡windows,官網上只給了十分簡要的安裝說明,不過基本等於沒說呀,大概意思是自己去找個編譯器編譯后使用吧。。。版主又借助在海外的優勢,四處google怎樣在windows下安裝libspatialindex,找了半天全是國外網友的疑問,卻沒人回答......看來大部分人都是用的Linux,版主這么小白還用windows簡直就是錯誤......國內網友似乎也無人問津這個問題。找了半天似乎只有國外一個大神成功了,不過我按照他的步驟試了很久,還是不行。這里還是把地址貼出來,僅供參考:

http://lists.gispython.org/pipermail/spatialindex/2012-December/000336.html,有興趣有時間的同學可以一試睡覺

其實!其實!其實!哪里會有那么多麻煩事...發現了另一個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:” 

這明明就是說win版本的,這個Dll文件已經預編譯進去了呀!!!根本不需要自己去裝libspatialindex......

下邊正式說安裝步驟,廢話有點多了:

1. 這里 http://www.lfd.uci.edu/~gohlke/pythonlibs/#rtree 下載對應版本的Rtree的whl安裝包,注意是python2.7還是3.5,注意電腦是32還是64位。可以放在電腦任意位置

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

 

 

 

 

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM