2

I'm new to both GDAL and Linux. I have installed GDAL on my Linux mint PC. I am able to use regular GDAL commands in the terminal, but when I use python based commands,such as gdal_calc.py I get the following error:

Traceback (most recent call last):
  File "/usr/bin/gdal_calc.py", line 51, in <module>
    from osgeo import gdal
  File "/usr/lib/python2.7/dist-packages/osgeo/__init__.py", line 21, in <module>
    _gdal = swig_import_helper()
  File "/usr/lib/python2.7/dist-packages/osgeo/__init__.py", line 17, in swig_import_helper
    _mod = imp.load_module('_gdal', fp, pathname, description)
ImportError: /usr/lib/x86_64-linux-gnu/libspatialite.so.7: undefined symbol: freexl_version

I get the same error when I try from osgeo import gdal in a Python session. I am presuming that this has something to do with the locations of the gdal python scripts, or something related to spatialite (although I am not sure what spatialite has to do with this command). I also have QGIS and PostGIS installed, which presumably could cause some conflicts.

I have searched numerous sources, but can't find the cause of this error. I wonder if someone might be able to point me in the right direction.

8
  • What happens if you type import gdal in a python session? Commented May 24, 2017 at 14:46
  • I get the same error using 'import gdal'. In an idle session, if I type 'from osgeo import gdal', I get a ===RESTART: Shell=== message, then when inputting 'import gdal' again, I get the same initial error.
    – David
    Commented May 24, 2017 at 15:25
  • Can you run the gdal utilities using subprocess.call()? This could be a temporary hack if you don't have time on your side
    – GeoMonkey
    Commented May 24, 2017 at 19:17
  • Would this help this particular problem. I'm not trying to write a python script. I'm just trying to use the GDAL python commands (gdal_calc.py; gdal_edit.py, etc) in the terminal. If they don't work in the terminal, I'm not sure they would work from a subprocess.call().
    – David
    Commented May 24, 2017 at 21:22
  • I misunderstood. Yeah, I don't think subprocess would work. Where is your python installation from? I get mine via anaconda/miniconda and its always worked fine. Miniconda/anaconda has the added benefit of allowing you to add other packages (gdal utilities, i.e gdal_translate) easily
    – GeoMonkey
    Commented May 26, 2017 at 3:03

1 Answer 1

1

Are you running the command directly (i.e ~/gdal_edit.py ) or are you passing the the script to the correct interpreter (i.e ~/bin/python3 gdal_edit.py) If I just run ~/gdal_edit.py I get a very similar error:

~/bin$ gdal_edit.py
Traceback (most recent call last):File "~/bin/gdal_edit.py", line 34, in <module> from osgeo import gdal
  File "~/lib/python3.6/site-packages/GDAL-2.2.1-py3.6-linux-x86_64.egg/osgeo/__init__.py", line 21, in <module>
_gdal = swig_import_helper()
  File "~/lib/python3.6/site-packages/GDAL-2.2.1-py3.6-linux-x86_64.egg/osgeo/__init__.py", line 17, in swig_import_helper
_mod = imp.load_module('_gdal', fp, pathname, description)
  File "~/lib/python3.6/site-packages/GDAL-2.2.1-py3.6-linux-x86_64.egg/osgeo/_gdal.py", line 7, in <module>
__bootstrap__()
  File "~/lib/python3.6/site-packages/GDAL-2.2.1-py3.6-linux-x86_64.egg/osgeo/_gdal.py", line 6, in __bootstrap__
imp.load_dynamic(__name__,__file__)
ImportError: ~/lib/python3.6/site-packages/GDAL-2.2.1-py3.6- 
linux-x86_64.egg/osgeo/_gdal.cpython-36m-x86_64-linux-gnu.so: undefined symbol: PyUnicode_AsUTF8String

But when I pass it the script to the interpreter:

  sguinn@zoot:~/bin$ ~/bin/python3 gdal_edit.py
Usage: gdal_edit [--help-general] [-ro] [-a_srs srs_def] [-a_ullr ulx uly lrx lry]
             [-tr xres yres] [-unsetgt] [-a_nodata value] [-unsetnodata]
             [-offset value] [-scale value]
             [-unsetstats] [-stats] [-approx_stats]
             [-gcp pixel line easting northing [elevation]]*
             [-unsetmd] [-oo NAME=VALUE]* [-mo "META-TAG=VALUE"]*  datasetname

Edit in place various information of an existing GDAL dataset.

It works as expected. Hope this helps

1
  • Thanks for that. I have actually reinstalled my distribution recently. I will test this once I have installed gdal.
    – David
    Commented Aug 1, 2018 at 17:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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