设为首页 收藏本站
查看: 1469|回复: 0

[经验分享] windows环境下安装Python的Rtree包

[复制链接]

尚未签到

发表于 2017-6-29 20:43:25 | 显示全部楼层 |阅读模式
  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
  如图所示:
DSC0000.jpg

  当然,这个错误并不是版主没有使用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,有兴趣有时间的同学可以一试 DSC0001.gif
  其实!其实!其实!哪里会有那么多麻烦事...发现了另一个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:”
DSC0002.jpg

  这明明就是说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安装包的位置,自己安装的时候根据具体情况改一下即可。
  然后两秒安装成功。
   DSC0003.jpg
  此时版主不知是该笑还是该哭,只觉得自己笨的要死...
  不过,至今也没找到怎样正确在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
  
  
  
  

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-389433-1-1.html 上篇帖子: 记一次排错,windows日志 模块 DLL C:\Windows\system32\inetsrv\aspnetcore.dll 未能加载。返回的数据为错误信 下篇帖子: [转]Windows 下常用盗版软件的替代免费软件列表
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表