Python gdal undefined symbol GDALRasterBandGetVirt

2019-07-03 16:27发布

问题:

I'm trying to use Python GDAL bindings. When naively installing bindings through pip, installation fails with error: 'VSIFTruncateL' was not declared in this scope, probably due to a mismatch of the installed headers and the python bindings version. The proposed solution elsewhere is to install the exact same version through pip. However, my system has gdal-1.7.3, and there are no 1.7.3 bindings. Installing 1.7.1 bindings leads to successful compilation, but attempting to run leads to undefined symbol: GDALRasterBandGetVirtualMem. Therefore, I installed 1.11.1 from source and compiled the latest bindings against it. Compilation and installation appears to work, but importing does not:

In [2]: import osgeo
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-2-26b16a6d02ad> in <module>()
----> 1 import osgeo

/export/data/home/gholl/venv/gerrit/lib/python3.4/site-packages/osgeo/__init__.py in <module>()
     19                 fp.close()
     20             return _mod
---> 21     _gdal = swig_import_helper()
     22     del swig_import_helper
     23 else:

/export/data/home/gholl/venv/gerrit/lib/python3.4/site-packages/osgeo/__init__.py in swig_import_helper()
     15         if fp is not None:
     16             try:
---> 17                 _mod = imp.load_module('_gdal', fp, pathname, description)
     18             finally:
     19                 fp.close()

/export/data/home/gholl/venv/gerrit/lib64/python3.4/imp.py in load_module(name, file, filename, details)
    241                 return load_dynamic(name, filename, opened_file)
    242         else:
--> 243             return load_dynamic(name, filename, file)
    244     elif type_ == PKG_DIRECTORY:
    245         return load_package(name, filename)

ImportError: /export/data/home/gholl/venv/gerrit/lib/python3.4/site-packages/osgeo/_gdal.cpython-34m.so: undefined symbol: GDALRasterBandGetVirtualMem

I'm at a loss now. What else can I try to use gdal and its Python bindings?

(The system is Scientific Linux release 6.6 (Carbon) on which I do not have system administrator access.)

回答1:

If a gdal version is already installed, this problem will occur even if you have linked against the version installed in ~/.local.

A solution is given at a Planet MYSQL post here:

In this case, we can tell the linker to preload our newer 1.11.0 library in our shell this way:

export LD_PRELOAD=/usr/local/lib/libgdal.so.1

Or, in my case,

export LD_PRELOAD="$HOME/.local/lib/libgdal.so.1"

Indeed, this solves the problem.



回答2:

I run: export LD_PRELOAD=/usr/lib/libgdal.so.1 before pythod command, it's fixed



标签: python gdal