I have a Django app configured with GeoDjango that is failing on CircleCI 2.0 builds with the following error:
django.core.exceptions.ImproperlyConfigured: Could not find the GDAL library. Is GDAL installed? If it is, try setting GDAL_LIBRARY_PATH in your settings.
However, when I remove 'django.contrib.gis'
from DJANGO_APPS
in settings.py
the build runs successfully.
Are there additional steps for configuring GDAL in CircleCI outside of the postgres and GDAL docker images? I (perhaps incorrectly) assumed that GDAL would be found after the docker image was installed. Below is my 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
I fixed it by adding the following:
apt-get update && apt-get install -y \
gdal-bin python-gdal python3-gdal
right where you run 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
I am not familiar with Docker, but I've had my fair share of issues installing GDAL. Typically, when I have had to setup an environment which required GDAL in Django, I've followed the following steps (roughly).
First I run these commands, to install the GDAL library and set up the headers before installing the python library:
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
Next, somewhere inside my reqs.txt there's this line:
GDAL==2.1.0 # replace the version with the one you get from gdal-config
I install the packages in my reqs.txt:
pip install -r reqs.txt
Usually this is what it takes for me to set up GDAL so that I'm able to use django.contrib.gis
.
I hope this is of help to you.
The problem is that your third image is running in a separate container and GDAL is not available in the first one.
I made geodjango tests running using this docker image wooyek/geodjango
from Docker Hub.
Here is the beginning of my 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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With