[GIS] Unable to install Python 3.4 gdal bindings on CentOS

centosgdalinstallationpython

I can easily install GDAL and Python bindings on a Windows machine, but I can not reproduce the same thing on a CentOS machine. The problem is I want to use Python 3.4 (Python 2.7 is too old and outdated for me). So, I have two versions of Python on my CentOS machine and if I do

# update-alternatives --config python

I see such a picture:

+ 1 /usr/bin/python2.7
* 2 /usr/bin/python3.4

So, Python 2.7 is now active and when I do this:

# yum install gdal-python

everything works ok, except one little fact – gdal is installed for Python 2.7. If however, I switch to Python 3.4 and run the same command, I see multiple errors in the console, like

 except OSError, e:     
 SyntaxError: invalid sytax

I do not know what to do with all this. What I want is just to be able to use gdal with Python 3.4.

Best Answer

Here are two ways I have accomplished this using pip (if you do not have pip you must first do yum install python3-pip.

# using gdal package
yum install gdal-devel
export CPLUS_INCLUDE_PATH=/usr/include/gdal  # path from `gdal-config --cflags`
export C_INCLUDE_PATH=/usr/include/gdal
pip3 install GDAL==$(gdal-config --version | awk -F'[.]' '{print $1"."$2}')

# using pygdal package
yum install gdal-devel
pip3 install pygdal="`gdal-config --version`.*"