-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathinstall_geo.sh
More file actions
executable file
·45 lines (39 loc) · 1.97 KB
/
Copy pathinstall_geo.sh
File metadata and controls
executable file
·45 lines (39 loc) · 1.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/bin/bash
# Installs the GDAL Python package matching the currently installed system GDAL.
#
# Usage:
# bash install_geo.sh
#
# Prerequisites (run once per machine/codespace before this script):
# Debian/Ubuntu: sudo apt-get install -y libgdal-dev gdal-bin
# macOS: brew install gdal
# Windows: install OSGeo4W or download GDAL binaries from https://www.gisinternals.com/
set -euo pipefail
if ! command -v gdal-config &>/dev/null; then
echo "ERROR: gdal-config not found."
echo "Please install the system GDAL development libraries first:"
echo " Debian/Ubuntu: sudo apt-get install -y libgdal-dev gdal-bin"
echo " macOS: brew install gdal"
exit 1
fi
GDAL_VERSION=$(gdal-config --version)
echo "System GDAL version: ${GDAL_VERSION}"
# GDAL < 3.3 Python bindings use the deprecated 'use_2to3' setuptools feature,
# which was removed in setuptools 58+ and is incompatible with Python 3.12.
MAJOR=$(echo "${GDAL_VERSION}" | cut -d. -f1)
MINOR=$(echo "${GDAL_VERSION}" | cut -d. -f2)
if [[ "${MAJOR}" -lt 3 ]] || [[ "${MAJOR}" -eq 3 && "${MINOR}" -lt 3 ]]; then
echo "ERROR: System GDAL ${GDAL_VERSION} is too old. Python 3.12 requires GDAL >= 3.3."
echo "Debian Bullseye only ships GDAL 3.2 — upgrade to Debian Bookworm (or use a"
echo "newer apt source) to get a compatible GDAL version."
exit 1
fi
echo "Installing Python gdal==${GDAL_VERSION} into the current environment..."
# numpy must be <2.0 for GDAL <= 3.8 — the _gdal_array extension was compiled
# against the numpy 1.x ABI and will fail to import with numpy 2.x.
# --no-build-isolation ensures numpy is visible during the source build so that
# the _gdal_array C extension is actually compiled (isolated environments lack
# numpy and silently skip that extension, causing "cannot import _gdal_array").
uv pip install "numpy<2.0"
uv pip install --no-build-isolation --no-binary gdal --no-cache "gdal==${GDAL_VERSION}"
echo "Done. GDAL Python package installed successfully."