Hi, I got weird import behaviour from my pex: I c...
# general
h
Hi, I got weird import behaviour from my pex: I created a multi stage docker image (deb + src) for my pants-built pex file. Everything is working except for an import bug, where my code tries to import geo_pandas which imports typing module from python. However instead it tries to import typing module from open cv. After that I got an exception because I do not have all dependencies installed which are required for open cv. This is also the reason I found out about the error. I'll give you the error log and the docker file. Hope someone can explain.
Copy code
2025-10-10T06:11:32.122Z
File "/usr/lib/python3.12/multiprocessing/process.py", line 314, in _bootstrap
2025-10-10T06:11:32.122Z
self.run()
2025-10-10T06:11:32.122Z
File "/usr/lib/python3.12/multiprocessing/process.py", line 108, in run
2025-10-10T06:11:32.122Z
self._target(*self._args, **self._kwargs)
2025-10-10T06:11:32.122Z
File "/usr/lib/python3.12/concurrent/futures/process.py", line 251, in _process_worker
2025-10-10T06:11:32.122Z
call_item = call_queue.get(block=True)
2025-10-10T06:11:32.122Z
^^^^^^^^^^^^^^^^^^^^^^^^^^
2025-10-10T06:11:32.122Z
File "/usr/lib/python3.12/multiprocessing/queues.py", line 122, in get
2025-10-10T06:11:32.122Z
return _ForkingPickler.loads(res)
2025-10-10T06:11:32.122Z
^^^^^^^^^^^^^^^^^^^^^^^^^^
2025-10-10T06:11:32.122Z
File "/workspaces/job/update_layer/lib/python3.12/site-packages/geofileops/__init__.py", line 10, in <module>
2025-10-10T06:11:32.122Z
import geopandas._compat as gpd_compat
2025-10-10T06:11:32.122Z
File "/workspaces/job/update_layer/lib/python3.12/site-packages/geopandas/__init__.py", line 3, in <module>
2025-10-10T06:11:32.122Z
from geopandas.geoseries import GeoSeries
2025-10-10T06:11:32.122Z
File "/workspaces/job/update_layer/lib/python3.12/site-packages/geopandas/geoseries.py", line 3, in <module>
2025-10-10T06:11:32.122Z
import typing
2025-10-10T06:11:32.122Z
File "/workspaces/job/update_layer/lib/python3.12/site-packages/cv2/typing/__init__.py", line 61, in <module>
2025-10-10T06:11:32.122Z
import cv2.mat_wrapper
2025-10-10T06:11:32.122Z
ImportError: libGL.so.1: cannot open shared object file: No such file or directory
Copy code
FROM ubuntu:${VARIANT} AS base
ARG PYTHON_MAJOR_VERSION

FROM base AS layer-deps
COPY jobs/update_layer-deps.pex /deps.pex
RUN PEX_TOOLS=1 python${PYTHON_MAJOR_VERSION} /deps.pex venv --scope=deps --collisions-ok --compile --rm all /workspaces/jobs/update_layer

FROM base AS layer-srcs
ARG PYTHON_MAJOR_VERSION
COPY jobs/update_layer-srcs.pex /srcs.pex
RUN PEX_TOOLS=1 python${PYTHON_MAJOR_VERSION} /srcs.pex venv --scope=srcs --compile --rm all /workspaces/jobs/update_layer

FROM base
COPY --from=layer-deps /workspaces/jobs/update_layer /workspaces/jobs/update_layer
COPY --from=layer-srcs /workspaces/jobs/update_layer /workspaces/jobs/update_layer

WORKDIR /workspaces/jobs_geo_import/
c
I created a multi stage docker image
Are you implying that this error only occurs with multi-stage images? Or "regular" ones as well?
h
I should check this but this could be a reason