赞
踩
最近做空间数据ETL工具时需要在服务器上配置python环境,在安装GDAL包时各种报错,google查阅了诸多资料,总结安装步骤如下:
GDAL需要依赖PROJ.4和GEOS。 依次下载准备好PROJ.4, GEOS, GDAL的源码包并解压。
tar xvf proj-6.2.1.tar.gz
tar xvf geos-3.7.3.tar.bz2
tar xvf GDAL-3.0.4.tar.gz
./configure
make
make install
./configure
make
make install
./configure
make
make install
然后进入 gdal解压文件的swig/python/目录下,执行:
python3 setup.py build
python3 setup.py install
执行完毕后,安装成功。
验证是否可导入gdal的相关包,发现报错:
>> from osgeo import ogr
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.7/site-packages/GDAL-3.0.4-py3.7-linux-x86_64.egg/osgeo/__init__.py", line 41, in <module>
_gdal = swig_import_helper()
File "/usr/local/lib/python3.7/site-packages/GDAL-3.0.4-py3.7-linux-x86_64.egg/osgeo/__init__.py", line 24, in swig_import_helper
_mod = imp.load_module('_gdal', fp, pathname, description)
File "/usr/local/lib/python3.7/imp.py", line 242, in load_module
return load_dynamic(name, filename, file)
File "/usr/local/lib/python3.7/imp.py", line 342, in load_dynamic
return _load(spec)
ImportError: libgdal.so.26: cannot open shared object file: No such file or directory
查了一下错误原因,原来是系统不知道GDAL共享库的加载路径。在~/.bashrc中加入一行: export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib
,然后执行source .bashrc
。问题解决,大功告成。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。