Problem
I have a gdal2tiles.bat file that says
@echo off
call "%OSGEO4W_ROOT%\bin\o4w_env.bat"
python "%OSGEO4W_ROOT%\apps\Python39\Scripts\gdal2tiles.py" %*
However, when I run the script from Powershell as gdal2tiles earth.tif
or gdal2tiles.bat earth.tif
, the error message says
The system cannot find the path specified. python: can't open file 'C:\apps\Python39\Scripts\gdal2tiles.py': [Errno 2] No such file or directory
Workaround
I edit the .bat file to put the file path of the .py file like the code below. I run it and it says The system cannot find the path specified.
then the script runs as intended with correct output.
@echo off
call "%OSGEO4W_ROOT%\bin\o4w_env.bat"
python "C:\OSGeo4W\apps\Python39\Scripts\gdal2tiles.py" %*
However, the gdal2tiles.py is just one of the many Python scripts in the folder. If I need to run a different script, I need to edit its .bat file again.
My previous post is similar to this https://gis.stackexchange.com/q/414053/146811
What's a good fix that doesn't need me to edit all the .bat files?