Well today, I finally succeeded. The following recipe seems to work for GDAL 1.8.1. It assumes that you have virtualenv and the virtualenvwrapper already installed.
(1) Build and install GDAL with Python bindings on your system
GDAL_VER=1.8.1 GDAL_PATH=/usr/local/gdal/$GDAL_VER GEOS_VER=3.2.2 GEOS_PATH=/usr/local/geos/$GEOS_VER mkdir ~/src/gdal cd ~/src/gdal wget http://download.osgeo.org/gdal/gdal-$GDAL_VER.tar.gz tar xzf gdal-$GDAL_VER.tar.gz cd gdal-$GDAL_VER ./configure --prefix=$GDAL_PATH --with-geos=$GEOS_PATH/bin/geos-config --with-python >& log_configure.out make >& log_make.out make install >& log_make_install.out sudo sh -c "echo $GDAL_PATH'/lib' > /etc/ld.so.conf.d/gdal.conf" sudo ldconfig
(2) Create a Python Virtual Environment
mkvirtualenv --no-site-packages osgeo-test
(3) Create a symbolic link from within the virtual environment to gdal-config
This is needed because the setup.py file of the GDAL Python bindings requires gdal-config.# create a symbolic link in the virtual environment to the specific version of GDAL that you want to use (osgeo-test)$ ln -s ~/src/gdal/gdal-1.8.1/apps/gdal-config ~/.virtualenvs/osgeo-test/bin/gdal-config
(4) Download the GDAL Python package using PIP
Download, but don't install, since we need to configure the build extension parameters.(osgeo-test)$ pip install --no-install GDAL
(5) Set the build extension parameters using setup.py
(osgeo-test)$ cd ~/.virtualenvs/osgeo-test/build/GDAL (osgeo-test)$ python setup.py build_ext --gdal-config=/usr/local/gdal/1.8.1/bin/gdal-config --library-dirs=/usr/local/gdal/1.8.1/lib --libraries=gdal --include-dirs=/usr/local/gdal/1.8.1/include
(6) Install the configured package using PIP
(osgeo-test)$ cd (osgeo-test)$ pip install --no-download GDAL
(7) test it out
(osgeo-test)$ cd (osgeo-test)$ python Python 2.6.5 (r265:79063, Apr 16 2010, 13:57:41) [GCC 4.4.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> from osgeo import gdal >>> gdal.__version__ '1.8.1' >>>