矩池云安装gdal五种解决方案

1、最快最靠谱的是conda

conda install gdal

命令行conda/pip search gdal查看版本,选择合适的版本,例如:conda search gdal 命令行conda/pip
install gdal=版本号,注意加上版本号,否则可能安装上老版本(windows/linux都可用。例如:conda install
gdal=3.0.0

2、源码编译

(1)下载GDAL安装包(在官网上下载即可 http://www.gdal.org ,官网有下载链接但不知道为什么有时候会打不开,http://download.osgeo.org/gdal/)

wget http://download.osgeo.org/gdal/2.0.0/gdal-2.0.0.tar.gz
tar -xzvf gdal-2.0.0.tar.gz
cd gdal-2.0.0
./configure(./configure --with-python 可以让python版本的gdal在make时安装)
make
make install(如果有权限不足不能写入的话就sudo make install)

(2)将依赖的动态库和静态库添加到LD_LIBRARY_PATH环境变量中去。编辑bash的用户配置文件:

vim ~/.bashrc

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

(3)直接运行gdalinfo,如果出现下面图片则是安装成功。

(4)让GDAL可以在python下使用

进入到/你的目录/gdal-2.0.0/swig/python目录下

python setup.py build
python setup.py install

在python环境中运行:import osgeo

可能会提示的错误:ImportError: No module named _gdal

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

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

find / -name gdal.py
gedit /etc/profile
/etc/profile

3、pip install直接安装pygdal

感觉网上大部分的教程都不好使,直接pip install gdal会报错,通过安装pygdal就能用。

本人ubuntu16.04

安装依赖库:

apt-get install libgdal1i libgdal1-dev libgdal-dev

现在运行gdal-config --version来获取apt-get为您提供的版本。 例如,我得到1.11.3

pip install pygdal==1.11.3

但用gdal-config --version中的任何内容替换版本。 注意:您可能会收到错误消息

Could not find a version that satisfies the requirement pygdal1.11.3
(from versions: 1.8.1.0, 1.8.1.1, 1.8.1.2, 1.8.1.3, 1.9.2.0, 1.9.2.1,
1.9.2.3, 1.10.0.0, 1.10.0.1, 1.10.0.3, 1.10.1.0, 1.10.1.1, 1.10.1.3, 1.11.0.0, 1.11.0.1, 1.11.0.3, 1.11.1.0, 1.11.1.1, 1.11.1.3, 1.11.2.1, 1.11.2.3, 1.11.3.3, 1.11.4.3, 2.1.0.3) No matching distribution found for pygdal
1.11.3

如果发生这种情况,请再次运行pip install,但仍保持匹配的最高版本。

例如 在这种情况下:

pip install pygdal==1.11.3.3

安装成功后

>>> from osgeo import gdal

4、stackoverflow

记录一下:参考这个安装成功了

https://stackoverflow.com/questions/38630474/error-while-installing-gdal

gdal-config --version

Then run this commands:

pip install --download="some_path" GDAL
cd some_path
tar -xvzf GDAL-<version>.tar.gz
cd GDAL-<version>
python setup.py build_ext --include-dirs=/usr/include/gdal/

5、conda直接安装fiona

该方法是在遇到:

ImportError: libgeos-3.4.2.so: cannot open shared object file: No such
file or directory

这个问题时发现的,github上也有人遇到了相同的问题,应该是gdal的相关依赖出现了版本的问题,在把libgeos安装到3.4.2版本后还会有其他的依赖问题,可以尝试逐个解决,最方便的方法就是:

conda uninstall gdal

卸载重新安装fiona

conda install fiona

fiona: Fiona is designed to be simple and dependable. It focuses on
reading and writing data in standard Python IO style and relies upon
familiar Python types and protocols such as files, dictionaries,
mappings, and iterators instead of classes specific to OGR. Fiona can
read and write real-world data using multi-layered GIS formats and
zipped virtual file systems and integrates readily with other Python
GIS packages such as pyproj, Rtree, and Shapely. Fiona is supported
only on CPython versions 2.7 and 3.4+.

然后anaconda会把相关的库都安装好。

参考文章

Ubuntu18.04 + python 环境安装gdal的若干方法和遇到的问题

ubuntu-GDAL安装踩坑记

posted @ 2020-11-09 16:25  矩池云  阅读(1204)  评论(0编辑  收藏  举报