由於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