pythondockercythonpyproj

Python package install fails on docker image python:3.11-alpine : Error compiling cython file


I just had a problem that started Monday 12/05/2025, i have a custom python package on a registry that i've been using since a while, the installation of this package with pip on docker base image python:3.11-alpine been failing even though nothing has changed ( i even reverted to old versions still getting the same error)

Error stack:

Collecting jsonschema<5,>=4.22.0 (from gpf-common-point-cloud==1.10.0->-r requirements/base-gpf.txt (line 3))
  Downloading jsonschema-4.23.0-py3-none-any.whl.metadata (7.9 kB)
Collecting pdal==3.4.5 (from gpf-common-point-cloud==1.10.0->-r requirements/base-gpf.txt (line 3))
  Downloading pdal-3.4.5.tar.gz (89 kB)
  Installing build dependencies: started
  Installing build dependencies: finished with status 'done'
  Getting requirements to build wheel: started
  Getting requirements to build wheel: finished with status 'done'
  Installing backend dependencies: started
  Installing backend dependencies: finished with status 'done'
  Preparing metadata (pyproject.toml): started
  Preparing metadata (pyproject.toml): finished with status 'done'
Collecting pyproj (from gpf-common-point-cloud==1.10.0->-r requirements/base-gpf.txt (line 3))
  Downloading pyproj-3.7.1-cp311-cp311-musllinux_1_2_x86_64.whl.metadata (31 kB)
Collecting shapely (from gpf-common-point-cloud==1.10.0->-r requirements/base-gpf.txt (line 3))
  Downloading shapely-2.1.0-cp311-cp311-musllinux_1_2_x86_64.whl.metadata (6.7 kB)
Collecting numpy>=1.22 (from pdal==3.4.5->gpf-common-point-cloud==1.10.0->-r requirements/base-gpf.txt (line 3))
  Using cached numpy-2.2.5-cp311-cp311-musllinux_1_2_x86_64.whl.metadata (62 kB)
Collecting boto3<1.34,>=1.28 (from gpf-entrepot-toolbelt<1.14.0,>=1.13.0->gpf-common-point-cloud==1.10.0->-r requirements/base-gpf.txt (line 3))
  Downloading boto3-1.33.13-py3-none-any.whl.metadata (6.7 kB)
Collecting boto3-stubs<1.34,>=1.28 (from boto3-stubs[s3]<1.34,>=1.28->gpf-entrepot-toolbelt<1.14.0,>=1.13.0->gpf-common-point-cloud==1.10.0->-r requirements/base-gpf.txt (line 3))
  Downloading boto3_stubs-1.33.13-py3-none-any.whl.metadata (138 kB)
Collecting psycopg<3.2,>=3.1 (from gpf-entrepot-toolbelt<1.14.0,>=1.13.0->gpf-common-point-cloud==1.10.0->-r requirements/base-gpf.txt (line 3))
  Downloading psycopg-3.1.20-py3-none-any.whl.metadata (4.2 kB)
Collecting shapely (from gpf-common-point-cloud==1.10.0->-r requirements/base-gpf.txt (line 3))
  Downloading shapely-2.0.7.tar.gz (283 kB)
  Installing build dependencies: started
  Installing build dependencies: finished with status 'done'
  Getting requirements to build wheel: started
  Getting requirements to build wheel: finished with status 'done'
  Preparing metadata (pyproject.toml): started
  Preparing metadata (pyproject.toml): finished with status 'done'
Collecting deprecated>=1.2.14 (from gpf-entrepot-toolbelt<1.14.0,>=1.13.0->gpf-common-point-cloud==1.10.0->-r requirements/base-gpf.txt (line 3))
  Downloading Deprecated-1.2.18-py2.py3-none-any.whl.metadata (5.7 kB)
Collecting pyproj (from gpf-common-point-cloud==1.10.0->-r requirements/base-gpf.txt (line 3))
  Downloading pyproj-3.6.1.tar.gz (225 kB)
  Installing build dependencies: started
  Installing build dependencies: finished with status 'done'
  Getting requirements to build wheel: started
  Getting requirements to build wheel: finished with status 'error'
  error: subprocess-exited-with-error
  
  × Getting requirements to build wheel did not run successfully.
  │ exit code: 1
  ╰─> [62 lines of output]
      warning: pyproj/_compat.pxd:4:0: The 'IF' statement is deprecated and will be removed in a future Cython version. Consider using runtime conditions or C macros instead. See https://github.com/cython/cython/issues/4310
      warning: pyproj/_compat.pyx:20:0: The 'IF' statement is deprecated and will be removed in a future Cython version. Consider using runtime conditions or C macros instead. See https://github.com/cython/cython/issues/4310
      warning: pyproj/_crs.pyx:2347:0: The 'IF' statement is deprecated and will be removed in a future Cython version. Consider using runtime conditions or C macros instead. See https://github.com/cython/cython/issues/4310
      warning: pyproj/_crs.pyx:2406:8: The 'IF' statement is deprecated and will be removed in a future Cython version. Consider using runtime conditions or C macros instead. See https://github.com/cython/cython/issues/4310
      warning: pyproj/_compat.pxd:4:0: The 'IF' statement is deprecated and will be removed in a future Cython version. Consider using runtime conditions or C macros instead. See https://github.com/cython/cython/issues/4310
      warning: pyproj/_datadir.pxd:3:25: noexcept clause is ignored for function returning Python object
      warning: pyproj/_datadir.pxd:3:25: noexcept clause is ignored for function returning Python object
      warning: pyproj/_datadir.pyx:96:95: The keyword 'nogil' should appear at the end of the function signature line. Placing it before 'except' or 'noexcept' will be disallowed in a future version of Cython.
      warning: pyproj/_compat.pxd:4:0: The 'IF' statement is deprecated and will be removed in a future Cython version. Consider using runtime conditions or C macros instead. See https://github.com/cython/cython/issues/4310
      warning: pyproj/_datadir.pyx:81:25: noexcept clause is ignored for function returning Python object
      warning: pyproj/_compat.pxd:4:0: The 'IF' statement is deprecated and will be removed in a future Cython version. Consider using runtime conditions or C macros instead. See https://github.com/cython/cython/issues/4310
      
      Error compiling Cython file:
      ------------------------------------------------------------
      ...
          def __init__(self, double a, double f, bint sphere, double b, double es):
              geod_init(&self._geod_geodesic, <double> a, <double> f)
              self.a = a
              self.f = f
              # convert 'a' only for initstring
              a_str = int(a) if a.is_integer() else a
                      ^
      ------------------------------------------------------------
      
      pyproj/_geod.pyx:94:16: Unsafe C derivative of temporary Python reference used in conditional expression
      
      Error compiling Cython file:
      ------------------------------------------------------------
      ...
              geod_init(&self._geod_geodesic, <double> a, <double> f)
              self.a = a
              self.f = f
              # convert 'a' only for initstring
              a_str = int(a) if a.is_integer() else a
              f_str = int(f) if f.is_integer() else f
                      ^
      ------------------------------------------------------------
      
      pyproj/_geod.pyx:95:16: Unsafe C derivative of temporary Python reference used in conditional expression
      Traceback (most recent call last):
        File "/usr/local/lib/python3.11/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 353, in <module>
          main()
        File "/usr/local/lib/python3.11/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 335, in main
          json_out['return_val'] = hook(**hook_input['kwargs'])
                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "/usr/local/lib/python3.11/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 118, in get_requires_for_build_wheel
          return hook(config_settings)
                 ^^^^^^^^^^^^^^^^^^^^^
        File "/tmp/pip-build-env-domw9i3i/overlay/lib/python3.11/site-packages/setuptools/build_meta.py", line 331, in get_requires_for_build_wheel
          return self._get_build_requires(config_settings, requirements=[])
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "/tmp/pip-build-env-domw9i3i/overlay/lib/python3.11/site-packages/setuptools/build_meta.py", line 301, in _get_build_requires
          self.run_setup()
        File "/tmp/pip-build-env-domw9i3i/overlay/lib/python3.11/site-packages/setuptools/build_meta.py", line 317, in run_setup
          exec(code, locals())
        File "<string>", line 248, in <module>
        File "<string>", line 203, in get_extension_modules
        File "/tmp/pip-build-env-domw9i3i/overlay/lib/python3.11/site-packages/Cython/Build/Dependencies.py", line 1145, in cythonize
          cythonize_one(*args)
        File "/tmp/pip-build-env-domw9i3i/overlay/lib/python3.11/site-packages/Cython/Build/Dependencies.py", line 1289, in cythonize_one
          raise CompileError(None, pyx_file)
      Cython.Compiler.Errors.CompileError: pyproj/_geod.pyx
      [end of output]
  
  note: This error originates from a subprocess, and is likely not a problem with pip.
error: subprocess-exited-with-error

× Getting requirements to build wheel did not run successfully.
│ exit code: 1
╰─> See above for output.

note: This error originates from a subprocess, and is likely not a problem with pip.

this is the dockerfile i'm using:

FROM python:3.11-alpine

# Write .pyc files only once. See: https://stackoverflow.com/a/60797635/2556577
ENV PYTHONDONTWRITEBYTECODE 1
# Make sure that stdout and stderr are not buffered. See: https://stackoverflow.com/a/59812588/2556577
ENV PYTHONUNBUFFERED 1
# Remove assert statements and any code conditional on __debug__. See: https://docs.python.org/3/using/cmdline.html#cmdoption-O
ENV PYTHONOPTIMIZE 2

# PIP - DISABLE VERSION CHECK
ENV PIP_DISABLE_PIP_VERSION_CHECK 1
# PIP - EXTRA_INDEX_URL
ENV PIP_EXTRA_INDEX_URL https://internal_gitlab_pypi_registry
# PIP - HIDE PROGRESS BAR
ENV PIP_PROGRESS_BAR off
# PIP - RETRIES
ENV PIP_RETRIES 1
# PIP - DISABLE WARNING ABOUT ROOT USER
ENV PIP_ROOT_USER_ACTION ignore

WORKDIR /user/app

RUN apk add --no-cache gcc musl-dev linux-headers python3-dev libstdc++ && \
    apk add --no-cache g++ && \
    apk add --no-cache geos-dev proj-dev proj-util

RUN apk add --no-cache gdal pdal-dev pdal

RUN pdal --version

# Building pdal wrench
RUN apk add --no-cache git cmake make
RUN git clone https://github.com/PDAL/wrench.git

RUN mkdir ./wrench/build
WORKDIR ./wrench/build
RUN cmake ..
RUN make
ENV PATH="/user/app/wrench/build:${PATH}"

# Building untwine
WORKDIR /opt
RUN git clone --branch 1.4.0 --single-branch https://github.com/hobuinc/untwine.git
RUN mkdir /opt/untwine/build
WORKDIR /opt/untwine/build
RUN cmake ..
RUN make
ENV PATH="/opt/untwine/build/bin:${PATH}"

What make me doubt that the problem might come from the docker image is that the installation works on another project that use a different docker image based on --ubuntu 22: condaforge/mambaforge:latest or maybe it's an obscure Cython thing since i don't really familiar with it.

Thanks for your time everyone, i will really appreciate any help


Solution

  • I've encountered this exact issue before. The problem stems from Cython's stricter type checking in version 3.0+ conflicting with older pyproj builds. So, try to add this before your pip install requirements

    RUN pip install "Cython<3.0.0" "pyproj>=3.7.1"