0
votes

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!

3
Welcome to SO! Please take the time to go through stackoverflow.com/help/asking. - Dan Cornilescu
Standard environment? - Dan Cornilescu
Standard environment yes. - samuq
Thanks for welcoming! - samuq

3 Answers

2
votes

From What compiler can I use to build GDAL/OGR?

GDAL/OGR is written in ANSI C and C++. It can be compiled with all modern C/C++ compilers.

Which means it's incompatible with the (1st generation/python 2.7) standard environment Pure Python sandbox requirement:

All code for the Python runtime environment must be pure Python, and not include any C extensions or other code that must be compiled.

You may want to look at the flexible environment instead. Probably with a custom runtime, see Up-to-date pip with AppEngine Python flex env?

1
votes

Google App Engine's standard environment for Python27 only supports a specific set of third-party libraries that use C-extensions, listed here. pygdal is not in the list.

You may want to look into the Python3 standard runtime, though it is in beta. It allows you to install arbitrary third-party libraries.

0
votes

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