gdal源码安装(ubuntu)
1、安装依赖proj
# 配置环境变量
(base) root@FIB:~# export PKG_CONFIG_PATH=/usr/local/anaconda3/lib/pkgconfig/:$PKG_CONFIG_PATH
# 下载源码包
(base) root@FIB:~# wget https://github.com/OSGeo/PROJ/releases/download/6.2.0/proj-6.2.0.tar.gz
# 解压压缩包
(base) root@FIB:~# tar -xf proj-6.2.0.tar.gz
(base) root@FIB:~# cd proj-6.2.0/
#创建安装目录
(base) root@FIB:~/proj-6.2.0# mkdir -p /usr/local/proj
#编译安装
(base) root@FIB:~/proj-6.2.0# ./configure --prefix=/usr/local/proj
(base) root@FIB:~/proj-6.2.0# make
(base) root@FIB:~/proj-6.2.0# make install
2、安装gdal
# 下载源码包
(base) root@FIB:~# wget http://download.osgeo.org/gdal/3.0.1/gdal-3.0.1.tar.gz
# 解压压缩包
(base) root@FIB:~# tar -xf gdal-3.0.1.tar.gz
(base) root@FIB:~# cd gdal-3.0.1/
#创建安装目录
(base) root@FIB:~/gdal-3.0.1# mkdir -p /usr/local/gdal
#编译安装
(base) root@FIB:~/gdal-3.0.1# ./configure --with-proj=/usr/local/proj --prefix=/usr/local/gdal
(base) root@FIB:~/gdal-3.0.1# make
(base) root@FIB:~/gdal-3.0.1# make install
# 配置环境变量
(base) root@FIB:~/gdal-3.0.1# export PATH=/usr/local/gdal/bin/:$PATH
(base) root@FIB:~/gdal-3.0.1# export LD_LIBRARY_PATH=/usr/local/gdal/lib/:$LD_LIBRARY_PATH
# 安装python版的gdal
(base) root@FIB:~/gdal-3.0.1# cd swig/python/
(base) root@FIB:~/gdal-3.0.1/swig/python# python setup.py build
(base) root@FIB:~/gdal-3.0.1/swig/python# python setup.py install
# 生成指定变量 (gdal位置 显示安装结束前 Installed /usr/.../.egg)
(base) root@FIB:~/gdal-3.0.1/swig/python# export PYTHONPATH=/usr/local/anaconda3/lib/python3.8/site-packages/GDAL-3.0.1-py3.8-linux-x86_64.egg/osgeo/:$PYTHONPATH
# 最后 import gdal 测试
(base) root@FIB:~/gdal-3.0.1/swig/python# python
Python 3.8.3 (default, Jul 2 2020, 16:21:59)
[GCC 7.3.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import gdal
>>> exit()
3、配置环境变量
(base) root@FIB:~# vim /etc/profile
(base) root@FIB:~# tail -4 /etc/profile
export PKG_CONFIG_PATH=/usr/local/anaconda3/lib/pkgconfig/:$PKG_CONFIG_PATH
export PATH=/usr/local/gdal/bin/:$PATH
export LD_LIBRARY_PATH=/usr/local/gdal/lib/:$LD_LIBRARY_PATH
export PYTHONPATH=/usr/local/anaconda3/lib/python3.8/site-packages/GDAL-3.0.1-py3.8-linux-x86_64.egg/osgeo/:$PYTHONPATH
#使环境变量立刻生效
(base) root@FIB:~# source /etc/profile
现在还有个问题,就是只能在gdal-3.0.1/swig/python/
目录下才可以调用import gdal
,没精力搞明白了,有兴趣的小伙伴评论区见