Skip to content

Instantly share code, notes, and snippets.

@hervenivon
Last active April 15, 2022 11:48
Show Gist options
  • Save hervenivon/fe3a327bc28b142e51beb38ef11844c0 to your computer and use it in GitHub Desktop.
Save hervenivon/fe3a327bc28b142e51beb38ef11844c0 to your computer and use it in GitHub Desktop.
Install GEOS, PROJ4 & GDAL on amazon linux
export PYTHON_VERSION=3.4.3
export PYTHON_SHORT_VERSION=3.4
export GEOS_VERSION=3.6.2
export GDAL_VERSION=2.2.2
export PROJ4_VERSION=4.9.3
sudo yum-config-manager --enable epel
sudo yum install gdal-python
sudo yum -y install make automake gcc gcc-c++ libcurl-devel proj-devel geos-devel
# Compilation work for geos
mkdir -p "/tmp/geos-${GEOS_VERSION}-build"
cd "/tmp/geos-${GEOS_VERSION}-build"
curl -o "geos-${GEOS_VERSION}.tar.bz2" \
"http://download.osgeo.org/geos/geos-${GEOS_VERSION}.tar.bz2" \
&& bunzip2 "geos-${GEOS_VERSION}.tar.bz2" \
&& tar xvf "geos-${GEOS_VERSION}.tar"
cd "/tmp/geos-${GEOS_VERSION}-build/geos-${GEOS_VERSION}"
./configure --prefix=/usr/local/geos
# Make in parallel with 2x the number of processors.
make -j $(( 2 * $(cat /proc/cpuinfo | egrep ^processor | wc -l) )) \
&& sudo make install \
&& sudo ldconfig
# Compiltation worf for proj4
mkdir -p "/tmp/proj-${PROJ4_VERSION}-build"
cd "/tmp/proj-${PROJ4_VERSION}-build"
curl -o "proj-${PROJ4_VERSION}.tar.gz" \
"http://download.osgeo.org/proj/proj-${PROJ4_VERSION}.tar.gz" \
&& tar xfz "proj-${PROJ4_VERSION}.tar.gz"
cd "/tmp/proj-${PROJ4_VERSION}-build/proj-${PROJ4_VERSION}"
./configure --prefix=/usr/local/proj4
# Make in parallel with 2x the number of processors.
make -j $(( 2 * $(cat /proc/cpuinfo | egrep ^processor | wc -l) )) \
&& sudo make install \
&& sudo ldconfig
# Compilation work for GDAL
pip${PYTHON_SHORT_VERSION} install numpy
mkdir -p "/tmp/gdal-${GDAL_VERSION}-build"
cd "/tmp/gdal-${GDAL_VERSION}-build"
curl -o "gdal-${GDAL_VERSION}.tar.gz" \
"http://download.osgeo.org/gdal/${GDAL_VERSION}/gdal-${GDAL_VERSION}.tar.gz" \
&& tar xfz "gdal-${GDAL_VERSION}.tar.gz"
cd "/tmp/gdal-${GDAL_VERSION}-build/gdal-${GDAL_VERSION}"
./configure --prefix=/usr/local/gdal \
--with-curl=yes \
--with-static-proj4=/usr/local/proj4 \
--with-python=yes
# Make in parallel with 2x the number of processors.
make -j $(( 2 * $(cat /proc/cpuinfo | egrep ^processor | wc -l) )) \
&& sudo make install \
&& sudo ldconfig
# Configuring environment
export PATH="/usr/local/gdal/bin:$PATH"
export LD_LIBRARY_PATH="/usr/local/proj4/lib:/usr/local/gdal/lib:$LD_LIBRARY_PATH"
export GDAL_DATA="/usr/local/gdal/share/gdal"
cd swig/python/
python${PYTHON_SHORT_VERSION} setup.py build
sudo python${PYTHON_SHORT_VERSION} setup.py install
@hervenivon
Copy link
Author

Another way is to use conda which is much simplier if it works for you!

Here on an AMI Linux for Machine Learning:

sudo /home/ec2-user/src/anaconda3/bin/conda create --yes -n gdal python=3.6 gdal opencv scipy pandas pylint affine pytest affine shapely pep8 cython keras-gpu -c 'conda-forge'
source ~/src/anaconda3/bin/activate gdal

Thank you @Ngoguey42

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment