Opened 9 months ago

Closed 9 months ago

Last modified 9 months ago

#594 closed defect (worksforme)

GDAL Python scripts can not be run

Reported by: alexbruy Owned by: osgeo4w-dev@…
Priority: major Component: Package
Version: Keywords: gdal, python, scripts
Cc: gioman

Description

Looks like there is something wrong with GDAL Python scripts (e.g. gdal_merge.py, gdal_calc.py etc) setup in OSGeo4W.

When trying to run any of the Processing tools in QGIS which are based on GDAL Python scripts, they fails with message saying that corresponding GDAL script is not found. Same happens with trying to run them from the OSGeo4W shell directly.

Here is steps to reproduce using OSGeo4W shell:

  1. open OSGeo4W shell
  2. setup Python by running py3_env.bat
  3. try to execute for example gdal_calc.py with
    python gdal_calc.py
    
  4. execution failed with error
    C:\>python gdal_calc.py
    (null): can't open file 'gdal_calc.py': [Errno 2] No such file or directory
    

Same error when running gdal_calc.py from QGIS Processing.

Related QGIS issue https://issues.qgis.org/issues/21210

Change History (4)

comment:1 Changed 9 months ago by jef

Did you install python3-gdal?

comment:2 Changed 9 months ago by alexbruy

Yes, python3-gdal 2.4.0-5 installed, GDAL scripts present in the %OSGEO4W_ROOT%\apps\Python37\Scripts and can be executed when full path specified.

comment:3 Changed 9 months ago by Mike Toews

Generally speaking, calling python script_name.py should normally show "python: can't open file 'script_name.py': [Errno 2] No such file or directory", unless that file exists in the current directory.

With OSGeo4w's Shell, these commands are normally run by their name without any extension:

C:\>gdal_calc
Usage: gdal_calc.py --calc=expression --outfile=out_filename [-A filename]
                    [--A_band=n] [-B...-Z filename] [other_options]
...

Internally, the Python scripts are usually run with a tiny BAT script, e.g. see where gdal_calc for the full path of the thing that CMD calls:

C:\>where gdal_calc
C:\OSGeo4W64\bin\gdal_calc.bat

C:\>cat C:\OSGeo4W64\bin\gdal_calc.bat
@echo off
call "%OSGEO4W_ROOT%\bin\o4w_env.bat"
python "%OSGEO4W_ROOT%\bin\gdal_calc.py" %*

comment:4 Changed 9 months ago by jef

Resolution: worksforme
Status: newclosed

The QGIS problem is fixed by running "python3 -m gdal_calc …"

Last edited 9 months ago by jef (previous) (diff)
Note: See TracTickets for help on using tickets.