我有一个配置有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.

但是,当我从'django.contrib.gis'中的DJANGO_APPS中删除settings.py时,构建成功运行。

除了postgres和GDAL docker 镜像之外,是否还有其他步骤在CircleCI中配置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

最佳答案

我通过添加以下内容修复了该问题:

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

关于django - Django,GDAL和CircleCI 2,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/48272384/

10-13 05:49