删除旧版本
bash
sudo apt remove libgdal*
sudo apt remove gdal*
sudo apt autoremove
下载geos、proj和gdal
https://github.com/libgeos/geos/releases
这里使用的是3.12.1版本:
https://github.com/OSGeo/PROJ/releases
这里使用的是9.3.0版本:
https://github.com/OSGeo/gdal/releases
这里使用的是3.7.3版本:
编译
安装依赖包
bash
sudo apt install libsqlite3-0 libtiff5 libtiff5-dev curl libcurl4 libcurl4-gnutls-dev
解压文件:
sudo tar xvfj geos-3.12.1.tar.bz2
sudo tar xvf proj-9.3.0.tar.gz
sudo tar xvf gdal-3.7.3.tar.gz
编译GEOS
bash
cd geos-3.12.1
sudo mkdir build
cd build
sudo cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr/local ..
sudo make -j20
sudo make install
编译PROJ
bash
cd proj-9.3.0
sudo mkdir build
cd build
sudo cmake ..
sudo cmake --build . --target install -- -j 20
编译GDAL
bash
cd gdal-3.7.3
sudo mkdir build
cd build
sudo cmake ..
sudo cmake --build . --target install -- -j 20
后续
bash
sudo vim /etc/profile
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib
source /etc/profile
python安装
pip install numpy
pip install gdal==3.7.3
测试
bash
$ python3
Python 3.8.10 (default, Sep 28 2021, 16:10:42)
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from osgeo import gdal
>>> from osgeo import ogr
>>> from osgeo import osr
>>> from osgeo import gdal_array
>>> from osgeo import gdalconst