几点要注意的坑:
前言:前期GDAL的编译
这部分内容网上很多,不细说了
下载好GEOS PROJ等包(要注意版本对应关系,我是geos3.6.2,proj 4.9.3, gdal 2.2.4),先把这两个库安装,即configure + make + make install
安装python-devel(cenos 中是python3-devel, ubuntu中是python-dev)
pip3 install numpy 先安装好numpy...
一、指定的python版本要对
GDAL在configure时,需要指定 --with-python=python3,直接写python往往会绑定到系统自带的python2上去,所以最好指定python3或具体路径
二、找不到Python.h
往往在make的最后出现fatal error: Python.h: No such file or directory #include “Python.h“
这时候要注意,在gdal编译前需要python-devel。同理,也要注意python的版本,例如CentOS系统下,要执行yum install python3-devel -y才行,安装完毕后,再次make编译gdal
三、python版GDAL安装
make成功后,进入同目录下swig/python,然后用python3执行 python3 setup.py build 和 python3 setup.py install,才能完成gdal库的安装
四、验证python-gdal是否安装成功
(1) pip3 list
(2) 进入python3, from osgeo import gdal
五、提示importError: libgdal.so.20: cannot open shared obejct file
这个是因为找不到gdal编译好的libgdal.so.20静态库,一般make install 后库会被复制到安装目录(默认/usr/local/lib),所以,只需要export LD_LIBRARY_PATH=/usr/local/lib;$LD_LIBRARY_PATH即可。当然,为避免每次都要执行这句,在 ~/.bashrc 文件中添加就好
六、提示No module named _gdal.py
网上很多人说这是因为numpy没有在gdal及其绑定模块之前安装,所以先卸载gdal,安装numpy,再安装gdal.
另一种方式是在gdal编译的目录下,会有osgeo文件夹,这里面存放的就有_gdal.py,所以export LD_LIBRARY_PATH=osgeo文件夹路径,即可。
"I have a dream and I make it beautiful
this is love just like chemical
I have a dream and I make it beautiful
and you now, take my breath away"
《Chemical Bus》——Escape Plan