Python中安装GDAL

  • 1. 安装步骤
    • 1.1 方法1
    • 1.2 方法2
  • 2. 测试
  • 3. 参考

1. 安装步骤

方法1更简单,但是也可能出现较多问题,方法2更直观一次成功。

1.1 方法1

步骤1,终端/命令行中输入:

pip install gdal

如果出现错误:

Traceback (most recent call last):File "/tmp/pip-install-h_n_kokk/gdal_0c5c253514974d76a20d2183c5b4798d/setup.py", line 188, in get_gdal_configreturn fetch_config(option, gdal_config=self.gdal_config)File "/tmp/pip-install-h_n_kokk/gdal_0c5c253514974d76a20d2183c5b4798d/setup.py", line 90, in fetch_configraise gdal_config_error(e)__main__.gdal_config_error: [Errno 2] No such file or directory: 'gdal-config': 'gdal-config'During handling of the above exception, another exception occurred:

步骤2,安装 libgdal-dev:

 sudo apt install libgdal-dev

重复步骤1,如果出现错误:

extensions/gdal_wrap.cpp:48261:97: error: ‘GVOT_MIN_TARGET_HEIGHT_FROM_DEM’ was not declared in this scopeSWIG_Python_SetConstant(d, "GVOT_MIN_TARGET_HEIGHT_FROM_DEM",SWIG_From_int(static_cast< int >(GVOT_MIN_TARGET_HEIGHT_FROM_DEM)));^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~extensions/gdal_wrap.cpp:48262:100: error: ‘GVOT_MIN_TARGET_HEIGHT_FROM_GROUND’ was not declared in this scopeSWIG_Python_SetConstant(d, "GVOT_MIN_TARGET_HEIGHT_FROM_GROUND",SWIG_From_int(static_cast< int >(GVOT_MIN_TARGET_HEIGHT_FROM_GROUND)));^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~extensions/gdal_wrap.cpp: At global scope:extensions/gdal_wrap.cpp:5383:15: warning: ‘MDArrayReadWriteCheckArguments’ defined but not used [-Wunused-variable]static CPLErr MDArrayReadWriteCheckArguments(GDALMDArrayHS* array,^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~extensions/gdal_wrap.cpp:5360:13: warning: ‘CheckNumericDataType’ defined but not used [-Wunused-variable]static bool CheckNumericDataType(GDALExtendedDataTypeHS* dt)^~~~~~~~~~~~~~~~~~~~error: command 'x86_64-linux-gnu-gcc' failed with exit status 1----------------------------------------
ERROR: Command errored out with exit status 1: /home/zwshi/PycharmProjects/LaserAltimetry/venv/bin/python -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-rw1cca2p/gdal_71f0a1fbeb04448fa91e2007642cbb8d/setup.py'"'"'; __file__='"'"'/tmp/pip-install-rw1cca2p/gdal_71f0a1fbeb04448fa91e2007642cbb8d/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-mcpr3nb_/install-record.txt --single-version-externally-managed --compile --install-headers /home/zwshi/PycharmProjects/LaserAltimetry/venv/include/site/python3.6/gdal Check the logs for full command output.

步骤3,安装gdal的依赖库:

sudo apt-get install gdal-bin libgdal-dev python3-gdal

然后,重复步骤1,应该就好了。

1.2 方法2

GDAL官网下载,下载地址:https://www.lfd.uci.edu/~gohlke/pythonlibs/#gdal
目前官网提供以下版本的GDAL库,win32代表32位系统,amd64代表64位操作系统,cp36代表你装的Python是3.6版本的,依次类推。

如果Python解释器已经安装,然后Windows在cmd中,cd到GDAL-3.4.3-cp38-cp38-win32.whl所在文件夹,输入命令:

pip install GDAL-3.4.3-cp38-cp38-win32.whl

我安装了Anaconda,在启动程序里,选择Anaconda prompt(myenv),然后cd到GDAL-3.4.3-cp38-cp38-win32.whl所在文件夹,然后输入命令:

pip install GDAL-3.4.3-cp38-cp38-win32.whl

下面命令是不行的

conda install GDAL-3.4.3-cp38-cp38-win32.whl

2. 测试

测试:

from __future__ import print_function
from osgeo import gdal
print("GDAL's version is:" + gdal.__version__)
print(gdal)

输出:

GDAL's version is:2.2.3
<module 'osgeo.gdal' from '/usr/lib/python3/dist-packages/osgeo/gdal.py'>

3. 参考

[1] ChatGPT. www.openai.com
[2] GDAL for python 教程
[3] 在Python中安装GDAL(最简单,最详细图文教程)
[4] Python配置和安装gdal库(Windows下)

Python中安装GDAL相关推荐

  1. 在Python中安装GDAL(最简单,最详细图文教程)

    在Python中安装GDAL(最简单,最详细图文教程) 今天是2021年1月20日.为了安装在pythong中安装GDAL,我浏览了几十个网页,发现有99%都是垃圾,浪费了我非常多的时间.最后我安装成 ...

  2. 【转载】在Python中安装GDAL(最简单,最详细图文教程)

    原文来自:https://blog.csdn.net/mojie002/article/details/112915275 第0步:在cmd中,直接输入pip install GDAL 安装不上.想这 ...

  3. cmd进入到python安装目录下_在python中安装basemap

    在python中安装basemap 1. 确保python环境安装完毕且已配置好环境变量 2. 安装geos: pip install geos 3. 下载.whl文件: (1)pyproj‑1.9. ...

  4. wrapper在python中_virtualenvwrapper如何在python中安装虚拟环境?

    上一篇我们讲过virtualenv在python中的安装虚拟环境,它还有另一个小伙伴virtualenvwrapper.如果大家感兴趣的话,可以边学边分析两者的不同,接下来开始我们今天的讲解. 一.使 ...

  5. 如何在Python中安装NumPy

    公众号-IT赶路人,专注分享与IT相关的知识! NumPy是Python编程不可或缺的一个库.在本文中,我们将学习如何在Python中安装NumPy.以下要点将在本文中介绍,让我们开始吧! 什么是Nu ...

  6. 树莓派python中安装numpy,pandas,torch,torchvision失败,ERROR: Could not find a version that satisfies the req

    树莓派python中安装numpy,pandas,torch,torchvision问题 安装失败现象 python通过pip安装torch错误ERROR: Could not find a vers ...

  7. Python中安装PyOpenGL:详细教程

    Python中安装PyOpenGL:详细教程 如果你对Python编程有一定的了解,并且在计算机图形学领域有所涉猎,你可能会使用到PyOpenGL.PyOpenGL是Python的一个OpenGL绑定 ...

  8. 股票交易接口 Python中安装并导入pandas

    Python中安装并导入pandas 金融市场往往充斥着海量的交易.运行等数据,同花顺iFinD数据接口通过链接iFinD数据库,能够批量获取数据用于分析,在针对资本运作.量化交易的研究中有着广泛的应 ...

  9. Pycharm中安装GDAL库

    1.安装GDAL库(更方便的方法请移步新文章) GDAL(Geospatial Data Abstraction Library)是一个在X/MIT许可协议下的开源栅格空间数据转换库.它利用抽象数据模 ...

最新文章

  1. Microsoft Visual C++ Compiler for Python
  2. QButtonGroup 的使用
  3. 安卓关于fragment切换后继续运行的问题!
  4. 【编程题目】调整数组顺序使奇数位于偶数前面
  5. 关于vue项目中添加less,less-loader不能运行的问题
  6. 挖掘城市ip_德国卡尔斯草莓农庄:旅游IP打造要创意更要形象!
  7. shell 编程中的判断
  8. 使用librtmp进行H264与AAC直播
  9. 插入…值(SELECT…FROM…)
  10. 内存陷阱 驯服C++中的野指针
  11. envi安装成功教程 附下载地址
  12. 2020年全国工业固体废物、危险废物产生量、利用处置量及防治措施分析[图]
  13. 【Opencv】图像分割——区域生长
  14. 计算机科学与技术专业宣传口号,十大经典深入人心科技类广告语
  15. HTML的文本格式标记
  16. 如何快速分割每段视频,并提取画面中任意一帧
  17. Jenkins-cents7.6 rpm安装
  18. @Profile注解详解
  19. Ip地址基础--全篇无废话
  20. m对比PSO,WPA,GWPA以及GWO四种优化算法的优化性能,优化目标函数为10个来自CEC2017的标准测试函数

热门文章

  1. 百度图片排名:SEO常用的5个技巧!
  2. 自动控制原理(1)-典型环节的传递函数
  3. 基于SPI的OLED显示
  4. 读书笔记(二十三):代码整洁
  5. JS一键复制粘贴功能
  6. 《网络运维基础知识手册》
  7. 运动控制器轴回零的配置与实现
  8. 关于电脑设置个性化此电脑属性打不开问题
  9. 点到超平面的距离简单证明
  10. python 计算牛顿差商,计算并化简牛顿插值多项式