How To Get Gdal Version Two To Work In Google Gcloud

If you are using Gcloud, by now you must have noticed that GDAL version two, needs more work to get it working on GCloud. This is so because the version of Python generally supported by GCloud is version 3.7 of which GDAL 2.X  requires Python 3.8 and above. For that reason, you will get the following error trying to run GDAL 2.X with Python 3.7:

File "/opt/python3.7/lib/python3.7/ctypes/init.py", line 377, in getattr func = self.getitem(name) File "/opt/python3.7/lib/python3.7/ctypes/init.py", line 382, in getitem func = self._FuncPtr((name_or_ordinal, self)) AttributeError: /usr/lib/libgdal.so.1: undefined symbol: OGR_F_GetFieldAsInteger64

To solve this problem is to run a custom runtime as explained here in google docs: https://cloud.google.com/appengine/docs/flexible/custom-runtimes Mainly what that means is getting your App.yaml file to run a custom runtime by creating your own docker image for deployment. It should be mentioned here too that, you'll be able to get this working on Gcloud Flex Environment or some other computer engine environment but not standard environment. That said, here is an example working app.yaml file setup:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
runtime: custom
entrypoint: gunicorn -b :8080 app.wsgi
env: flex # for Google Cloud Flexible App Engine

# any environment variables you want to pass to your application.
# accessible through os.environ['VARIABLE_NAME']
env_variables:
    <your environment variables>

beta_settings:
# from command >> gcloud sql instances describe DATABASE-NAME <<
  cloud_sql_instances: <Instance Name>

handlers:
- url: /.*
  script: auto
  secure: always
manual_scaling: 
  instances: 1

runtime_config:
  python_version: 3

And finally your docker container file:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
FROM python:3.8
EXPOSE 8080
ENV PYTHONUNBUFFERED 1

# Install GDAL dependencies
#RUN apt-get update && apt-get install --yes libgdal-dev
#apt-get install binutils libproj-dev gdal-bin
RUN apt-get update && apt-get install --reinstall -y \
  binutils \
  gdal-bin \
  python3-gdal \
  libproj-dev

# Update C env vars so compiler can find gdal
#ENV CPLUS_INCLUDE_PATH=/usr/include/gdal
#ENV C_INCLUDE_PATH=/usr/include/gdal
RUN export CPLUS_INCLUDE_PATH=/usr/include/gdal
RUN export C_INCLUDE_PATH=/usr/include/gdal


# Copy the application's requirements.txt and run pip to install all
# dependencies into the virtualenv.
ADD requirements.txt /app/requirements.txt
RUN pip install -r /app/requirements.txt
# Add the application source code.
ADD . .

# Run a WSGI server to serve the application. gunicorn must be declared as
# a dependency in requirements.txt.
CMD exec gunicorn --bind :8080 --workers 1 --threads 8 main:app --timeout 0 --preload

Related Posts

0 Comments

12345

    00