Home:ALL Converter>Python GDAL cannot find app GDAL on docker image

Python GDAL cannot find app GDAL on docker image

Ask Time:2022-08-13T02:29:54         Author:DVA

Json Formatter

I'm trying to build an application into a docker container that uses the OSGEO/GDAL libraries in Python, which are wrappers around the GDAL program. The GDAL program appears to install ok (at least Docker reports => CACHED [3/9] RUN apk add --no-cache gdal without any errors from the step that I can see) however, when I get to the step where pip is supposed to bring in the GDAL Python libraries, it fails looking for files that don't exist, which some initial searching shows is likely to mean it can't find the GDAL program. Does anyone know how to resolve or work around this?

Collecting GDAL~=3.5.1
#11 15.03   Downloading GDAL-3.5.1.tar.gz (752 kB)
#11 15.16      ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 752.4/752.4 KB 7.3 MB/s eta 0:00:00
#11 15.30   Preparing metadata (setup.py): started
#11 15.71   Preparing metadata (setup.py): finished with status 'error'
#11 15.73   error: subprocess-exited-with-error
#11 15.73   
#11 15.73   × python setup.py egg_info did not run successfully.
#11 15.73   │ exit code: 1
#11 15.73   ╰─> [120 lines of output]
#11 15.73       WARNING: numpy not available!  Array support will not be enabled
#11 15.73       running egg_info
#11 15.73       creating /tmp/pip-pip-egg-info-2jyd4zlx/GDAL.egg-info
#11 15.73       writing /tmp/pip-pip-egg-info-2jyd4zlx/GDAL.egg-info/PKG-INFO
#11 15.73       writing dependency_links to /tmp/pip-pip-egg-info-2jyd4zlx/GDAL.egg-info/dependency_links.txt
#11 15.73       writing requirements to /tmp/pip-pip-egg-info-2jyd4zlx/GDAL.egg-info/requires.txt
#11 15.73       writing top-level names to /tmp/pip-pip-egg-info-2jyd4zlx/GDAL.egg-info/top_level.txt
#11 15.73       writing manifest file '/tmp/pip-pip-egg-info-2jyd4zlx/GDAL.egg-info/SOURCES.txt'
#11 15.73       Traceback (most recent call last):
#11 15.73         File "/tmp/pip-install-tjr9j_9m/gdal_6b994752ac484434b194dfc7ccf64728/setup.py", line 105, in fetch_config
#11 15.73           p = subprocess.Popen([command, args], stdout=subprocess.PIPE)
#11 15.73         File "/usr/local/lib/python3.9/subprocess.py", line 951, in __init__
#11 15.73           self._execute_child(args, executable, preexec_fn, close_fds,
#11 15.73         File "/usr/local/lib/python3.9/subprocess.py", line 1821, in _execute_child
#11 15.73           raise child_exception_type(errno_num, err_msg, err_filename)
#11 15.73       FileNotFoundError: [Errno 2] No such file or directory: '../../apps/gdal-config'

Here's my dockerfile (the base image is non-negotiable, I'm afraid)

FROM python:3.9.12-alpine3.15

RUN apk add --no-cache gdal

RUN mkdir -p /usr/src/app/file
WORKDIR /usr/src/app
COPY requirements.txt /usr/src/app/
RUN pip install --no-cache-dir -r requirements.txt
COPY src/ /usr/src/app/src/
COPY main.py /usr/src/app/
CMD ["python", "main.py"]

The requirements.txt is as follows.

requests>= 2.25.0
numpy>=1.23.1
pillow>=9.2.0
GDAL~=3.5.1
DateTime~=4.3
bitstring~=3.1.9
behave~=1.2.6

I'm not sure if there is a way to install GDAL to a particular spot so that python can find it when installing its GDAL libraries, or if I need to give pip some kind of hint, or if something else entirely is going on. If anyone has worked with this library before inside a docker container, thanks in advance!

Author:DVA,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/73338409/python-gdal-cannot-find-app-gdal-on-docker-image
yy