0

I'm using GDAL 3.3.1 installed via OSGeo4w. I ran gdal2tiles.py world.tif but it said

gdal2tiles.py : The term 'gdal2tiles.py' is not recognized as the name of a cmdlet, function, script file, or operable
program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ gdal2tiles.py earth.tif
+ ~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (gdal2tiles.py:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

Attempts in solving

  • I reinstalled "python3-gdal: The GDAL/OGR Python3 Bindings and Scripts' via the OSGeo4W installer. Same error.
  • Add C:\OSGeo4W\apps\Python39\Scripts to the "Path" System Variable. No error but the gdal2tiles.py opens instead of running.The script is in this folder.
  • Add C:\OSGeo4W\apps\Python39\Lib\site-packages\osgeo_utils to the "Path" System Variable. No error but the gdal2tiles.py opens instead of running.The script is also in this folder.
  • Copy-Paste the gdal2tiles.py.tmpl, gdal2tiles.py, and gdal2tiles.bat to the C:\OSGeo4W\bin folder (which is also a "Path" System Variable). No error but the gdal2tiles.py opens instead of running

Related post gdal2tiles is not recognized as an internal or external command?

Any solutions?

7
  • 1
    Osgeo4W tries to make is easy for the users by configuring paths and environmental variables and by installing some helper batch files but you must have messed up the installation but you can have a try with python path/to/gdal2tiles.py.
    – user30184
    Oct 15, 2021 at 14:19
  • Just tried ` C:\OSGeo4W\apps\Python39\Scripts\gdal2tiles.py earth.tif` and it opened the script again instead of running correctly.
    – BallpenMan
    Oct 15, 2021 at 14:20
  • 1
    Read literally. The python is important. It kind of says "start python and run this script". Same kind of error here gis.stackexchange.com/questions/413629/….
    – user30184
    Oct 15, 2021 at 14:22
  • 1
    When you have C:\OSGeo4W\apps\Python39\Scripts in the path you can use just gdal2tiles or gdal2tiles.bat. Both mean the same, the batch file is running python gdal2tiles.pyfor you. Or then you can use the latter directly.
    – user30184
    Oct 15, 2021 at 15:14
  • 1
    As per the help center please do not include chit chat like thanks in your posts.
    – PolyGeo
    Oct 16, 2021 at 2:34

1 Answer 1

-1

A good workaround that doesn't need to type the full path of the Python script nor edit the .bat file is to to add the 'C:\OSGeo4W' to the "Path" system variable.

I can now run gdal2tiles and other scripts located in the C:\OSGeo4W\apps\Python39\Scripts folder just by running its name or its .bat file.

1
  • Don't do this unless you set every other environment variable that the osgeo batch files do. Just run the "osgeo shell" from the start menu and run things from there
    – mikewatt
    Mar 25, 2022 at 22:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.