Ubuntu 20.04 ImportError:没有名为 gdal 的模块

Ubuntu 20.04 ImportError:没有名为 gdal 的模块

我正在尝试在 Ubuntu 20.04 LTS 上使用 gdal 的 python2 绑定,但其存储库中没有 python-gdal 包,因此无法运行旧的 python2 应用程序。

我尝试从 Ubuntu 18.04 LTS 存储库下载并安装它:

sudo wget -c http://archive.ubuntu.com/ubuntu/pool/universe/g/gdal/python-gdal_2.2.3+dfsg-2_amd64.deb

sudo apt install ./python-gdal_2.2.3+dfsg-2_amd64.deb

但出现错误:

The following packages have unmet dependencies. python-gdal : Depends: gdal-abi-2-2-3 but it is not installable Depends: libgdal20 (>= 2.2.2) but it is not installable E: Unable to correct problems, you have held broken packages.

我也运行sudo apt-get dist-upgradeapt-cache policy python-gdal libgdal20输出:

python-gdal: Installed: (none) Candidate: (none) Version table: libgdal20: Installed: (none) Candidate: (none) Version table:

有没有什么办法可以无冲突地使用 python-gdal 在 Ubuntu 20 上运行应用程序?

答案1

可以为 Python 2 安装 GDAL,但我们需要手动获取许多依赖项:

mkdir -p ~/Downloads/gdal
cd ~/Downloads/gdal

wget -c http://security.ubuntu.com/ubuntu/pool/main/j/json-c/libjson-c3_0.12.1-1.3ubuntu0.3_amd64.deb
wget -c http://archive.ubuntu.com/ubuntu/pool/universe/a/armadillo/libarmadillo8_8.400.0+dfsg-2_amd64.deb
wget -c http://archive.ubuntu.com/ubuntu/pool/universe/p/proj/libproj12_4.9.3-2_amd64.deb
wget -c http://archive.ubuntu.com/ubuntu/pool/universe/libg/libgeotiff-dfsg/libgeotiff2_1.4.2-2build1_amd64.deb
wget -c http://archive.ubuntu.com/ubuntu/pool/universe/h/hdf5/libhdf5-100_1.10.0-patch1+docs-4_amd64.deb
wget -c http://archive.ubuntu.com/ubuntu/pool/universe/m/minizip/libminizip1_1.1-8build1_amd64.deb
wget -c http://security.ubuntu.com/ubuntu/pool/main/m/mysql-5.7/libmysqlclient20_5.7.31-0ubuntu0.18.04.1_amd64.deb
wget -c http://archive.ubuntu.com/ubuntu/pool/universe/n/netcdf/libnetcdf13_4.6.0-2build1_amd64.deb
wget -c http://archive.ubuntu.com/ubuntu/pool/universe/o/ogdi-dfsg/libogdi3.2_3.2.0+ds-2_amd64.deb
wget -c http://security.ubuntu.com/ubuntu/pool/main/p/poppler/libpoppler73_0.62.0-2ubuntu2.10_amd64.deb
wget -c http://archive.ubuntu.com/ubuntu/pool/universe/q/qhull/libqhull7_2015.2-4_amd64.deb

wget -c http://archive.ubuntu.com/ubuntu/pool/universe/g/gdal/gdal-data_2.2.3+dfsg-2_all.deb
wget -c http://archive.ubuntu.com/ubuntu/pool/universe/g/gdal/libgdal20_2.2.3+dfsg-2_amd64.deb
wget -c http://archive.ubuntu.com/ubuntu/pool/universe/g/gdal/python-gdal_2.2.3+dfsg-2_amd64.deb

sudo apt install ./*.deb

然后使用下面的单个长命令固定 GDAL 包版本:

cat <<EOF | sudo tee /etc/apt/preferences.d/pin-gdal
Package: gdal-data
Pin: version 2.2.3+dfsg-2
Pin-Priority: 1337

Package: libgdal20
Pin: version 2.2.3+dfsg-2
Pin-Priority: 1337

Package: python-gdal
Pin: version 2.2.3+dfsg-2
Pin-Priority: 1337
EOF

那么它就可以工作了。

相关内容