Opened 5 years ago

Closed 5 years ago

Last modified 5 years 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 by jef, 5 years ago

Did you install python3-gdal?

comment:2 by alexbruy, 5 years ago

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 by Mike Taves, 5 years ago

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 by jef, 5 years ago

Resolution: worksforme
Status: newclosed

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

Version 0, edited 5 years ago by jef (next)
Note: See TracTickets for help on using tickets.