windows環境下安裝Python的Rtree包

來源:互聯網
上載者:User

標籤:data   sys   setup   install   edit   default   test   apt   text   

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 updatesudo apt-get install curlsudo 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 xzcd spatialindex-src-1.8.5./configuremakesudo make installsudo 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

 

 

 

 

 

 

windows環境下安裝Python的Rtree包

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.