linux下gdal的python包的安装


由于python包是从C++包编译出来的,所以需要先下载源码进行编译安装。
1. gdal下载
http://download.osgeo.org/gdal/CURRENT/
sudo ./configure --with-python --with-geos=geos-config的路径
sudo make
sudo make install

 

注:安装失败重新编译之前,使用make clean清除一下上次的内容。

 

2. 然后进入到swig/python目录下
sudo python setup.py build
sudo python setup.py install


gdal帮助文档
https://pcjericks.github.io/py-gdalogr-cookbook/

 

错误排解

1. ImportError: No module named _gdal

使用sudo find / -name gdal.py查找所在位置

然后用import sys;sys.path查看是否包含当前路径,若不包含,添加到路径中

 

2. ImportError: libgdal.so.20: cannot open shared object file: No such file or directory

查找该文件所在路径

sudo find / -name libgdal.so.20

将路径添加到~/.bashrc中

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib

 

3. ERROR 6: GEOS support not enabled.

ogr库依赖GEOS包,需要首先安装GEOS,然后再安装gdal。详细可参见参考文章(http://scigeo.org/articles/howto-install-latest-geospatial-software-on-linux.html#gdal).

一定要下载3.5.0,因为3.4版本有bug。http://download.osgeo.org/geos/geos-3.5.0.tar.bz2

 

cd /opt/source
wget http://download.osgeo.org/geos/geos-3.5.0.tar.bz2
tar xvjf geos-3.3.8.tar.bz2 
cd geos-3.3.8
mkdir build
./configure --prefix=/opt/source/geos-3.5.0/build --enable-python
# compile
make -j$threads
# check compilation result (passes on Ubuntu; may get errors on CentOS, but probably still ok)
make check
# install into build dir
make install
# check install
./build/bin/geos-config --version

 

参考:

1. http://scigeo.org/articles/howto-install-latest-geospatial-software-on-linux.html#gdal

posted @ 2016-01-12 17:00  ottll  阅读(11796)  评论(0编辑  收藏  举报