App Engine: ImportError: No module named _gdal

App Engine: ImportError: No module named _gdal

如何在 Google App Engine 标准中启用像 GDAL 这样的 python 2.7 库?目前在 App Engine 的 lib 文件夹中有 linux python-modules,但是当尝试 运行 通过端点的代码时,App Engine 给出内部服务器错误:ImportError: No module named _gdal .我正在使用 pygdal 版本 2.2.3.3。 libgdal(pygdal 需要)是否也应该安装在 App Engine 上,如果是,该怎么做?我在 these instructions using this syntax: sudo pip install --target lib --requirement requirements.txt --ignore-installed as it says here 之后将 GDAL 在本地安装到 lib 文件夹中(在 windows10 上使用 ubuntu bash)。请帮忙!

Google App Engine 的标准环境 Python27 仅支持一组特定的使用 C 扩展的第三方库,已列出 herepygdal 不在列表中。

您可能想查看 Python3 标准运行时,尽管它在 beta 中。它允许您安装任意第三方库。

来自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.

这意味着它与 (1st generation/python 2.7) 标准环境 Pure Python 沙箱要求不兼容:

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

您可能想看看灵活的环境。可能使用自定义运行时,请参阅

修改 this 链接的答案 我设法让 GDAL 在 App Engine Flexible 中工作。 我的码头文件:

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

我的app.yaml-文件:

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-文件:

pygdal==1.11.3.3