我正在尝试将 Django 应用程序部署到 App Engine 柔性环境。我的 dockerfile 无法安装 GDAL。
这是我在运行 gcloud app deploy
时收到的错误消息:
File "/env/lib/python3.7/site-packages/django/contrib/gis/gdal/libgdal.py", line 42, in <module>
% '", "'.join(lib_names)
django.core.exceptions.ImproperlyConfigured: Could not find the GDAL library (tried "gdal", "GDAL", "gdal2.4.0", "gdal2.3.0", "gdal2.2.0", "gdal2.1.0", "gdal2.0.0"). Is GDAL installed? If it is, try setting GDAL_LIBRARY_PATH in your settings.
[2020-04-24 16:12:26 +0000] [8] [INFO] Worker exiting (pid: 8)
[2020-04-24 16:12:26 +0000] [1] [INFO] Shutting down: Master
[2020-04-24 16:12:26 +0000] [1] [INFO] Reason: Worker failed to boot.
这是我的 dockerfile:
FROM ubuntu:bionic
RUN apt-get update && apt-get install -y \
binutils \
gdal-bin \
python3-gdal \
ibgdal-dev \
libproj-dev
# 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.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.
RUN pip install -r 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 gunicorn -b :$PORT main:app
这是我的 app.yaml:
runtime: python
env: flex
entrypoint: gunicorn -b :$PORT main:app
runtime_config:
# You can also specify 2 for Python 2.7
python_version: 3.7
我知道我在问一个非常相似的问题,并且正在回答 here ,但提问者自己的解决方案似乎没有用。
最佳答案
对我来说,您似乎缺少正确的 gdal
安装。事实上,安装它可能有点棘手,但在 ubuntu
(也有 docker
)上,我通常有很好的安装经验 ubuntugis .
这是一个例子:
FROM ubuntu:bionic
RUN apt-get update && apt-get install -y \
software-properties-common \
python3 \
python3-dev \
python3-pip \
&& rm -rf /var/lib/apt/lists/*
RUN add-apt-repository ppa:ubuntugis/ppa
RUN apt-get update && apt-get install -y \
gdal-bin=2.4.2+dfsg-1~bionic0 \
python3-gdal \
&& rm -rf /var/lib/apt/lists/*
RUN apt-get update && apt-get install -y libpq-dev \
&& rm -rf /var/lib/apt/lists/*
...
关于docker - App Engine Flexible - Docker 文件无法安装 GDAL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61412885/