我有一个配置了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
我对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
。
我希望这对你有所帮助。
问题是您的第三个图像在一个单独的容器中运行,而第一个图像中没有GDAL。
我使用Docker Hub的docker image wooyek/geodjango
进行了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
我通过添加以下内容修复它:
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