[Gdal-dev] Using the 1.3.0 "ng" python bindings.

Kevin Ruland kruland at ku.edu
Wed Aug 17 10:49:43 EDT 2005


Hi all,

Since you're lurking here, you probably know that gdal 1.3.0 has been
officially released, and also that it contains two different python
bindings:  "Standard" and ng (next generation).  Although nobody has
blessed the term "Standard", I think it's more appropriate for now than
how I've been referring to it in the past ( "old school" or sometimes
"Frank's old bindings").  The Standard libraries are installed by
default and are still the "Officially Blessed Packages".  If you desire
to try to the ng bindings, then you will have to work a little harder.

The Standard and ng bindings cannot coexist easily on the same install. 
There are some tricks you can do to have them both and I will attempt to
describe that here.

When you install gdal-1.3.0 from source with ./configure && make
install, if configure finds a python, it will build and install the
Standard bindings in the appropriate location.  This is usually
/usr/lib/python2.4/site-packages/  (replace "2.4" with your python
version number...)  The files it installs are:

gdalconst.py
_gdalmodule.a
_gdalmodule.la
_gdalmodule.so
gdal.py
ogr.py
osr.py

Python will produce .pyc files for the .py's the first time they are loaded.

If you want to simply experiment with the ng bindings, you first need to
pick an alternative directory in which to install the python bindings. 
For the sake of discussion, lets say you want to install them in
/usr/local/gdal-ng/ and your gdal-1.3 source tree is in /tmp/gdal-1.3/. 
Then you need to do the following:

cd /tmp/gdal-1.3/swig/python
python setup.py install --prefix=/usr/local/gdal-ng/

This will put the following files in /usr/local/gdal-ng/:

gdalconst.py
_gdalconst.so
gdal.py
_gdal.so
ogr.py
_ogr.so
osr.py
_osr.so

Note: If you leave the --prefix off, these files will be installed in
/usr/lib/python2.4/site-packages and pretty much blow away the Standard
bindings.

If you want your python scripts to use the new bindings, you need to
prepend PYTHONPATH environment variable with /usr/local/gdal-ng.  To
switch back to using Standard bindings, don't export PYTHONPATH, or
remove the /usr/local/gdal-ng.

If you plan on installing the ng bindings in the standard location,
/usr/lib/python2.4/site-packages, the best thing to do is remove the
Standard binding files from this location first.  If you have a
'confused' installation, like mismatched .py and .so files, you will get
wierd errors when you first 'import gdal' in your python scripts.  The
complaints will most likely be about not being able to find symbols or
libraries.

Hope this helps.

Kevin



More information about the Gdal-dev mailing list