1

I have a Python script where I want to use the GDAL Python bindings.

Is it possible that I set the path to the bindings inside the script? Will that actually reflect the Python path?

For instance like this?

GDAL_LIBRARY_PATH = '/home/user123/lib/libgdal.so'
import gdal
print gdal.VersionInfo()
ustroetz
  • 5,802
  • 16
  • 47
  • 74
  • Why did you select a post about a different environment variable as a solution? That would certainly invite some explanation, at the least. – Pavel Šimerda Mar 30 '14 at 21:47
  • I thought it doesn't make a difference what the variable is actually called. As I understood Mikko's answer, any variable that is set after the script is started, will not be considered. But apparently that is not true. – ustroetz Mar 31 '14 at 06:20
  • I see. Actually, the key is *when* is the variable read. There are some variables that are used during initialization of the dynamic loader, the Python interpreter and libraries used by the interpreter, but most variables are being read later upon some action in the code, so you can actually set them in time ;). – Pavel Šimerda Mar 31 '14 at 06:24

1 Answers1

2

If it is an environment variable, I would set it up in os.environ before importing the module:

import os
os.environ['GDAL_LIBRARY_PATH'] = '/home/user123/lib/libgdal.so'
from osgeo import gdal
print(gdal.VersionInfo())

Mind you, this doesn't really do anything at all, since osgeo.gdal does not use this environment variable in any way. Django, however, uses a setting with this name.

Mike T
  • 41,085
  • 18
  • 152
  • 203