I'd really appreciate some guidance with this. I need to create some map illustrated tiles to use in leaflet.js for a small web-app I'm building. So far though I've lost about five days to installing and trying to configure the GDAL package to work for me.

The things I have tried so far (all on mac OS 10.15.4):

  1. download and installed GDAL2.4 package from http://www.kyngchaos.com/software/frameworks/
  2. Once that was done, I scratched my head a lot, as I couldn't really find any documentation as to how exactly I'm supposed to use the package - sure it's installed, but what does that give me exactly?
  3. After much searching and guessing, I found the script I wanted to run - gdal2tiles.py in my /Library/Frameworks/GDAL.Framework/Versions/2.4/Programs directory and from there was able to try running: $ python gdal2tiles.py [args] but it returned an error:

    File "gdal2tiles.py", line 52, in from osgeo import gdal ModuleNotFoundError: No module named 'osgeo'

  4. from there, I went down multiple rabbit holes
    • checking python versions (apparently I need to run 3.6 and I now am)
    • uninstalling/reinstalling all the things

But nothing fixes the problem.

Eventually I came across this post which suggests you can install GDAL2 via homebrew, which to me seems like it should be easy.. but no - whilst the process outlined was easy to follow, it left me with the same issue - I have GDAL installed, but no idea how to run the gdal2tiles.py script -I can still run the steps I outlined above and I get the same result. I'm guessing now I probably have multiple versions of GDAL installed which will bite me some other way.

Can anyone please help me with this? Essentially an idiots guide to installing and using GDAL would be perfect - all the info I can find during days of internet trawling seems to assume that I should know the answers already, but I'm not a Python dev, and have never run python packages before.

The main problems I would love solved would be:

  1. The first issue - how do I install or make the osgeo module available to my gdal2tiles script?
  2. If that's going to be too difficult, how can I access and use the gdal2tiles.py script through my homebrew installed version of GDAL2.

Some extra info

$ gdalinfo --version returns GDAL 2.4.2, released 2019/06/28

If I open a python 3.6.5 shell, and try import gdal I get ModuleNotFoundError (someone suggested that this would test if gdal was "available" to my python install).

I've added a bunch of stuff to my .bash_profile as I've tried out different things and I have no idea what is helping or hindering anymore, so my .bash_profile now includes:

export PATH=/usr/local/bin:/usr/local/sbin:~/bin:$PATH
export PATH=/Library/Frameworks/GDAL.framework/Programs:$PATH
export PATH=/Library/Frameworks/GDAL.framework/Versions/2.4/Programs:$PATH
export PATH=/Users/smallmighty/Library/Python/3.7/bin:$PATH
export PATH=/Library/Frameworks/GDAL.framework/Programs:/Library/Framework/PROJ.framework/Programs:/Library/Frameworks/SQLite3.framework/Programs:/Library/Frameworks/UnixImageIO.framework/Programs:$PATH
export PYTHONPATH="/Library/Frameworks/GDAL.framework/Programs/"
export PYTHONPATH="/Library/Frameworks/GDAL.framework/Versions/2.4/Programs"
  • Did you install the gdal python bindings? – Ian Turton May 23 '20 at 17:55
  • Hi @IanTurton no I didn't, I was unaware that it was a thing. I'm unable to find any relevant references to the process either. Do you have any useful resources you could point me to? – bitfidget May 25 '20 at 2:06
  • sorry, I'm not a mac user - but that would be the solution on windows and linux – Ian Turton May 25 '20 at 9:46

As a solution for this I'll recount my experience. I'm currently running OSX and needed to tile some geoTiffs. I noticed that my existing GDAL installation didn't have gdal2tiles so I opted to use the python library gdal2tiles. The execution was a little different and out of the box requires you to create a python script to run gdal2tiles.generate_tiles(...) The generated html pages are a good start but I'd suggest creating your own previewer with Leaflet following the instructions here

I'd also suggest using virtual environments with python which allows you to install libraries for specific projects instead of globally. Here's some instruction on this too https://docs.python.org/3/library/venv.html

Hopefully this helps.


Under Python, install osgeo. You can use pip install or conda install. Then it should work.

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.