我正在尝试将应用程序构建到使用Python中的OSGEO/GDAL库的坞容器中,这些库是GDAL程序的包装器。GDAL程序似乎安装ok (至少Docker报告=> CACHED [3/9] RUN apk add --no-cache gdal没有从我可以看到的步骤中出现任何错误),但是,当我到达pip应该引入GDAL库的步骤时,它将失败查找不存在的文件,一些初始搜索显示可能意味着它找不到GDAL程序。有人知道如何解决或解决这个问题吗?
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'这是我的文档(恐怕基本图像是不可商量的)。
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"]requirements.txt如下所示。
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我不确定是否有方法将GDAL安装到特定的位置,以便python在安装其GDAL库时能够找到它,或者我是否需要给出某种提示,或者是否有其他事情正在进行。如果以前有人在码头容器内使用过这个库,请提前感谢!
发布于 2022-08-12 23:37:41
问题的主要原因是缺少gdal-dev,这是一个单独安装python绑定的附加包。但是,一旦pip能够找到gdal并开始安装python库,这些库是由C代码构建的,映像中还需要一些额外的工具,加上一些环境设置来指向正确的位置。下面是最终起作用的dockerfile:
FROM python:3.9.12-alpine3.15
RUN apk add --no-cache gcc
RUN apk add --no-cache gdal
RUN apk add --no-cache gdal-dev
RUN apk add --no-cache build-base
RUN apk add --no-cache zlib
RUN export CPLUS_INCLUDE_PATH=/usr/include/gdal
RUN export C_INCLUDE_PATH=/usr/include/gdal
RUN export LDFLAGS="-L/usr/local/opt/zlib/lib"
RUN export CPPFLAGS="-I/usr/local/opt/zlib/include"
RUN mkdir -p /usr/src/app/file
WORKDIR /usr/src/app
COPY requirements.txt /usr/src/app/
RUN pip3 install --no-cache-dir -r requirements.txt
COPY src/ /usr/src/app/src/
COPY main.py /usr/src/app/
CMD ["python", "main.py"]最后,在requirements.txt中,当前的3.5.1GDAL绑定是针对Python3.10的,所以我不得不降低GDAL的级别,直到我找到一个没有错误构建的GDAL,因为基本图像中的Python是固定的。
https://stackoverflow.com/questions/73338409
复制相似问题