如何使GDAL与Google GCLOUD一起使用

问题描述

尝试将我的应用程序部署到gcloud应用程序引擎时出现以下错误。 整个问题出在试图将GDAL库添加到我的应用中。

文件“ /opt/python3.7/lib/python3.7/ctypes/init.py”,行377,在 getattr func = self。 getitem (名称)文件“ /opt/python3.7/lib/python3.7/ctypes/init.py”,第382行,位于 getitem func = self._FuncPtr(((name_or_ordinal,self))AttributeError:/usr/lib/libgdal.so.1:未定义的符号:OGR_F_GetFieldAsInteger64

我遵循了所有可能在网上找到的指示。但是似乎什么也没有。 这是我的app.yml文件:

runtime: custom

entrypoint: gunicorn -b :8080 app.wsgi
env: flex 

# any environment variables you want to pass to your application.
# accessible through os.environ['VARIABLE_NAME']
env_variables:
 ... 
  
beta_settings:
  cloud_sql_instances: site:asia-northeast2:site-db

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

runtime_config:
  python_version: 3 

和Dockerfile:

FROM gcr.io/google-appengine/python
#FROM python:3.7
#FROM python:3.8.0-slim-buster

EXPOSE 8080
ENV PYTHONUNBUFFERED 1

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


# 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

# Create a virtualenv for dependencies. This isolates these packages from
# system-level packages.
# Use -p python3 or -p python3.7 to select python version. Default is version 2.
RUN virtualenv /env -p python3

# 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 /app/requirements.txt
RUN pip install -r /app/requirements.txt
# Add the application source code.
ADD . /app

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

有人在这里帮助我。我需要做什么才能使它正常工作?

解决方法

在进行一些研究时,似乎出现错误是因为gdal库中有一个变量OGR_F_GetFieldAsInteger64,该变量已在2.0.0版[1]中引入,似乎您正在使用Python 3.7,对于此库,您需要Python 3.8版本。

您的问题可能有两种原因:

  1. 不是最新的python图像
  2. 库python-gdal

要解决您的问题,能否将图像“ gcr.io/google-appengine/python”替换为以下内容:

  • gcr.io/google-appengine/python:latest

还可以如下安装库python3-gdal而不是python-dgal:

apt-get update && apt-get install -y binutils gdal-bin python3-gdal

[1] https://github.com/OSGeo/gdal/commit/e5371b782e78f417cf0c9e551e381434ef1c9b73#diff-86e53c6a1e95018240ee21c6b8ce6832R361

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...