5

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.

  • What repo are you using? There's an earlier question that suggested using EPEL rather than ELGIS, for instance. Also what's the CentOS version? – mkennedy Dec 12 '16 at 20:45
  • I'm using CentOS 7. – Jacobian Dec 12 '16 at 20:52
  • I see that GDAL itself installed correctly - all those nice tools like gdalwarp, gdalinfo etc, are there and can be used. But the whole problem now is just in Python – Jacobian Dec 12 '16 at 20:54
  • I need to use gdal_retile.py and I need a bunch of modules from osgeo library, precisely, I need to do this - from osgeo import gdal, ogr, osr. This works ok in Python 2.7. But I can not install (or I do not know how) to install gdal-python for Python 3.x – Jacobian Dec 12 '16 at 20:56
  • As for the repo, yum list gdal-python says, that I'm using 1.11.4-10.rhel7. I do not even know if there is a repo for Python 3.X. – Jacobian Dec 12 '16 at 21:00
1

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`.*"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.