GDAL:python 中缺少 jp2 驱动程序

unn*_*nic 5 python gdal python-2.7

我需要在 python 中打开 .jp2 光栅文件。

我按照这些说明安装了 GDAL 。

使用命令行运行gdalinfo --formats列出JP2OpenJPEG驱动程序。gdalinfo filename.jp2返回预期输出。

但在Python中 import gdal data=gdal.Open('filename.jp2')

不返回任何内容(.tiff 有效)。

安装了另外 2 个使用 GDAL 的应用程序,因此我假设 python 使用了错误的 GDAL 安装。

我在 R 中遇到同样的问题,但我可以指出正确的安装 library(gdalUtils) gdal_chooseInstallation('JP2OpenJPEG')

有没有办法将 python 指向正确的安装或添加 jp2 的驱动程序?


Windows 10

Python 2.7

GDAL 2.1.0

Att*_*tti 0

我在同一个平台上,也面临着同样的问题。

我想我找到了一个解决方法:

安装 OSGEO4W https://trac.osgeo.org/osgeo4w/这将安装带有 JP2 驱动程序的 GDAL。

正确设置您的环境变量。看看 OSGEO 在 bin\O4W_ENV.bat 中做了什么,确保将它们添加到 Path 变量中。%OSGEO4W_ROOT%\bin;%WINDIR%\system32;%WINDIR%;%WINDIR%\WBem 顺序很重要,确保在 PATH 变量中按此顺序排列它们,否则可能会遇到问题。

测试做gdalinfo --format JP2OpenJPEG

由于 anaconda 可能会弄乱 PATH 变量,我再次在脚本中添加 osgeo home 。

# set environment osgeo_home_bin = "C:\\OSGeo4W64\\bin" # the path order matters so make sure OSGEO4W64 is the first one os.environ['PATH'] = ''.join([osgeo_home_bin,";",os.environ['PATH']])