Search code examples
python-2.7google-app-enginemodulegdal

App Engine: ImportError: No module named _gdal


How to enable python 2.7 library like GDAL in Google App Engine standard? Currently there are linux python-modules in lib-folder in app engine, but when trying to run the code through endpoints, app engine gives internal server error: ImportError: No module named _gdal. I'm using pygdal version 2.2.3.3. Should the libgdal (demanded for pygdal)be installed also on app engine, and if so, how to do it? I installed GDAL locally into lib folder (using ubuntu bash on windows10) following these instructions using this syntax: sudo pip install --target lib --requirement requirements.txt --ignore-installed as it says here. Please help!


Solution

  • Modifying this links' answer I managed to get GDAL working in App Engine Flexible. My dockerfile:

    FROM gcr.io/google-appengine/python
    
    RUN apt-get update && apt-get -y install libproj-dev libgdal-dev 
    RUN export CPLUS_INCLUDE_PATH=/usr/include/gdal
    RUN export C_INCLUDE_PATH=/usr/include/gdal
    RUN gdal-config --version
    # Create a virtualenv for dependencies. This isolates these packages from
    # system-level packages.
    RUN virtualenv /env -p python2.7
    
    # Setting these environment variables are the same as running
    # source /env/bin/activate.
    ENV VIRTUAL_ENV /env
    ENV PATH /env/bin:$PATH
    
    # Copy the application's requirements.txt and run pip to install all
    # dependencies into the virtualenv.
    ADD requirements.txt requirements.txt
    RUN pip install -r requirements.txt
    # Add the application source code.
    ADD . /app
    
    CMD gunicorn -t 120 -b :$PORT main:app
    

    My app.yaml-file:

    runtime: custom
    env: flex
    entrypoint: gunicorn -t 120 -b :$PORT main:app
    endpoints_api_service:
        name: xxxxx.com
    rollout_strategy: managed
    beta_settings:
        cloud_sql_instances: project:europe-north1:dbinstance
    runtime_config:
        python_version: 2
    

    requirements.text-file:

    pygdal==1.11.3.3