Search code examples
pythondockerubuntucmakegdal

gdal: build from source with python bindings in docker container


I’m struggling with building a gdal feature branch from source. My environment is docker with an ubuntu base image.

It builds fine, but invoking gdal2tiles.py throws the notorious

ModuleNotFoundError: No module named 'osgeo'

These are my build steps in my docker container:

RUN cmake -DBUILD_PYTHON_BINDINGS=ON -DCMAKE_BUILD_TYPE=Release ..
RUN cmake --build .
RUN cmake --build . --target install

Clearly I'm missing something for being able to import osgeo in python. But what is it?


Solution

  • I got it working. GDAL gets installed under the /usr/local prefix in my case, and Python didn't try to look for it there by default. Two solutions:

    • define PYTHONPATH=/usr/local/lib/python3/dist-packages

    • modify the first cmake invokation to set CMAKE_INSTALL_PREFIX to /usr:

    cmake -DBUILD_PYTHON_BINDINGS=ON -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr ..