代码之家  ›  专栏  ›  技术社区  ›  Anconia

Django、GDAL和CircleCI 2

  •  7
  • Anconia  · 技术社区  · 8 年前

    我有一个配置了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
    
    3 回复  |  直到 8 年前
        1
  •  3
  •   Robert Cinca    7 年前

    我通过添加以下内容来修复它:

    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
    
        2
  •  2
  •   BitParser    7 年前

    我对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
    

    接下来,在我的需求中的某个地方。txt有一行:

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

    我在我的需求中安装软件包。txt文件:

    pip install -r reqs.txt
    

    通常,这是我设置GDAL所需要的,以便我能够使用 django.contrib.gis .

    我希望这对你有帮助。

        3
  •  1
  •   ilse2005    7 年前

    问题是,您的第三个映像在单独的容器中运行,而GDAL在第一个容器中不可用。

    我用这个docker图像进行了geodjango测试 wooyek/geodjango 来自Docker Hub。

    这是我的 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
    
    推荐文章