Search code examples
pythongdal

Python fails to start a GDAL command


The error message is as follows:

python3.exe: No module named gdal2tiles

I downloaded the Osgeo4w installer and through this I installed GDAL\OGR 3.4 and python3-gdal libraries.

This is the command line I'm trying to launch:

python3 -m gdal2tiles -p mercator -z 0-10 -w none --processes=4 -r near --exclude --xyz -a 0.0 -n C:\myMap.geotiff C:\xyzTiles\ --config GDAL_PAM_ENABLED NO

If instead I explicit the path for gdal2tiles I get another error:

C:\OSGeo4W\apps\Python37\Scripts\gdal2tiles -p mercator -z 0-1 -w none --processes=4 -r near --exclude --xyz -a 0.0 -n C:\myMap.geotiff C:\xyzTiles\ --config GDAL_PAM_ENABLED NO

AttributeError: module 'main' has no attribute 'spec'


Solution

  • I was able to make the module visible to Python by moving to the scripts folder, inside the cmd file. I don't know if there is a way to set this path globally on the operating system. For now, however, I have solved it like this.

    CD C:\OSGeo4W\apps\Python37\Scripts

    python3 -m gdal2tiles -p mercator -z 0-10 -w none --processes=4 -r near --exclude --xyz -a 0.0 -n C:\myMap.geotiff C:\xyzTiles\ --config GDAL_PAM_ENABLED NO