Django、GDAL和CircleCI 2

7

我有一个配置了GeoDjango的Django应用程序,在CircleCI 2.0构建中出现以下错误:

django.core.exceptions.ImproperlyConfigured: Could not find the GDAL library. Is GDAL installed? If it is, try setting GDAL_LIBRARY_PATH in your settings.

然而,当我在settings.py中从DJANGO_APPS中删除'django.contrib.gis'时,构建成功运行。

除了使用postgres和GDAL docker镜像外,是否还有其他配置GDAL的步骤?我(可能错误地)假设在安装docker镜像后可以找到GDAL。以下是我的config.yml

version: 2
jobs:
  build:
    docker:
      - image: circleci/python:3.6.3

      - image: circleci/postgres:10.1-postgis
        environment:
        - POSTGRES_USER=ubuntu
        - POSTGRES_DB=myapp_test

      - image: geodata/gdal

    working_directory: ~/repo

    steps:
      - checkout

      # Download and cache dependencies
      - restore_cache:
          keys:
          - v1-dependencies-{{ checksum "requirements.txt" }}
          # fallback to using the latest cache if no exact match is found
          - v1-dependencies-

      - run:
          name: install dependencies
          command: |
            python3 -m venv venv
            . venv/bin/activate
            pip install -r requirements.txt
      - save_cache:
          paths:
            - ./venv
          key: v1-dependencies-{{ checksum "requirements.txt" }}

      - run:
          name: run tests
          command: |
            . venv/bin/activate
            python manage.py test
          environment:
            DATABASE_URL: "postgres://ubuntu@localhost:5432/myapp_test"

      - store_artifacts:
          path: test-reports
          destination: test-reports
3个回答

4
我通过添加以下内容解决了这个问题:
apt-get update && apt-get install -y \
gdal-bin python-gdal python3-gdal

就在你运行pip install的地方:

  - run:
      name: install dependencies
      command: |
        python3 -m venv venv
        . venv/bin/activate
        pip install -r requirements.txt
        apt-get update && apt-get install -y \
        gdal-bin python-gdal python3-gdal

1
这对我来说有效,使用了circleci/python:3.6镜像,尽管我不得不使用sudo: sudo apt-get update && sudo apt-get install -y gdal-bin python-gdal python3-gdal - Leila Hadj-Chikh

2

我不熟悉Docker,但我曾经遇到过安装GDAL的问题。通常,在需要在Django中设置GDAL的环境时,我会按照以下步骤进行(大致上)。

首先,运行以下命令以安装GDAL库并在安装Python库之前设置头文件:

sudo apt-get install libgdal-dev
gdal-config --version  # to see what version of GDAL you have
export CPLUS_INCLUDE_PATH=/usr/include/gdal
export C_INCLUDE_PATH=/usr/include/gdal

接下来,在我的reqs.txt文件中,有这样一行:

GDAL==2.1.0  # replace the version with the one you get from gdal-config

我在我的reqs.txt文件中安装了这些软件包:

pip install -r reqs.txt

通常我需要这样设置GDAL才能使用django.contrib.gis
希望这对你有帮助。

1
问题在于您的第三个图像正在单独的容器中运行,而GDAL在第一个容器中不可用。
我使用来自Docker Hub的wooyek/geodjango docker镜像运行geodjango测试。
这是我的config.yml的开头:
version: 2
jobs:
  build:
    docker:
      # image with pre-installed geodjango libs
      - image: wooyek/geodjango

      # postgis database
      - image: circleci/postgres:alpine-postgis-ram
        environment:
          POSTGRES_USER: postgres
          POSTGRES_DB: circle_test

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接