[osgeo4w-dev] PATH ordering for OSGeo4W Shell

Mike Toews mwtoews at gmail.com
Tue Jul 17 20:59:25 PDT 2012

On 18 July 2012 05:09, Matt Wilkie <matt.wilkie at gov.yk.ca> wrote:
> Short term, if you change your "Osgeo4W shell" menu and desktop shortcuts to
> point to
> C:\gnu\OSGeo4W\bin\o4w_env.bat
> instead of "C:\gnu\Osgeo4W\Osgeo4W.bat" it should insert the o4w dirs to the
> beginning of PATH. This is what Msys is doing.

Perfect, that is sort-of what I did. "o4w_env.bat" doesn't call
cmd.exe, so there is no shell if I update the shortcuts. Instead, I
modified Osgeo4W.bat (as Osgeo4W2.bat), which activates a cmd.exe:

@echo off
rem Root OSGEO4W home dir to the same directory this script exists in
set OSGEO4W_ROOT=%~dp0
rem Convert double backslashes to single
echo. & echo OSGEO4W home is %OSGEO4W_ROOT% & echo.

call %OSGEO4W_ROOT%bin\o4w_env.bat

rem List available o4w programs
rem but only if osgeo4w called without parameters
rem if [%1]==[] call o-help
@echo on

@if [%1]==[] (cmd.exe /k o-help) else (cmd /c "%*")

> However it's not a clean solution and there's still a chance of
> unpredictable crossover between the two different versions. For example
> something could call a library that isn't installed in Osgeo4W, but is
> present in GWV6, resulting in weird error messages, or worse, no error but
> silently return the wrong results. (I haven't actually seen this happen, I
> just know it's possible.)

So far, so good. Previously, if I tried to use gdal_polygonize:

Traceback (most recent call last):
  File "C:\gnu\OSGeo4W\\bin\gdal_polygonize.py", line 34, in <module>
    import gdal, ogr, osr
  File "C:\gnu\OSGeo4W\apps\Python27\lib\site-packages\gdal.py", line
2, in <module>
    from osgeo.gdal import deprecation_warn
  File "C:\gnu\OSGeo4W\apps\Python27\lib\site-packages\osgeo\__init__.py",
line 21, in <module>
    _gdal = swig_import_helper()
  File "C:\gnu\OSGeo4W\apps\Python27\lib\site-packages\osgeo\__init__.py",
line 17, in swig_import_helper
    _mod = imp.load_module('_gdal', fp, pathname, description)
ImportError: DLL load failed: The specified procedure could not be found.

Now with the modified version it works, loading the correct '_gdal'
library. This is a "fix" in my books.

Thanks for the tips!


More information about the osgeo4w-dev mailing list