I created a new conda environment with python version 3.7

Then installed

conda install -c conda-forge gdal=2.4

Then installed gdal2tiles

pip install gdal2tiles

and then python test.py

import gdal2tiles
gdal2tiles.generate_tiles('xyz.tif', 'output_dir')

but I am getting an error

AttributeError: module 'gdal2tiles' has no attribute 'generate_tiles'

It's the same method that I copied from the documentation but doesn't seem to work. https://pypi.org/project/gdal2tiles/


Unable to reproduce the issue with the following recipe

conda create --name gdaldemo python=3.7 -y
conda activate gdaldemo
conda install -c conda-forge gdal=2.4 -y
python -m pip install gdal2tiles
# Last command to check the issue
python -c "import gdal2tiles;print(gdal2tiles.generate_tiles)"

It seems you may have a conflict between GDAL native gdal2tiles.py and the package gdal2tiles.

If it echoes something when executing the following, it means your import gdal2tiles is using the default provided by GDAL and not the one by your 3rd party library.

python -c "import gdal2tiles;print(gdal2tiles.GDAL2Tiles)"
  • I still have the same error. Would that be a problem on windows machine? Which os it is that you are using? – user1298426 May 19 at 10:20
  • Ubuntu 18.04 64 bits – ThomasG77 May 19 at 10:24
  • Yes it echos <class 'gdal2tiles.GDAL2Tiles'> – user1298426 May 19 at 11:47
  • What python -c "import sys;print(sys.path);" returns? – ThomasG77 May 19 at 11:58
  • 1
    At the beginning of the Python script, do import sys;sys.path.insert(0, "C:\Users\usr\AppData\Local\Continuum\anaconda3\Lib\site-packages") After, you should be able to run your script. Clearly, not the best practice as normally it's related to Python messed environment(s) but too difficult to solve without this hackish approach... – ThomasG77 May 19 at 15:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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