dzsave method not installed when including libvips-dev in dockerfile

83 views Asked by At

I am fairly new to docker, and I am trying to make a docker image which gives me jupyter server with pyvips. The building of the image and running the container is going fine. Accessing the jupyterlab, including "import pyvips" in the notebook is working fine. However, when I try to use the "dzsave"-method there is an error concerning:

"no such operation dzsave"

"VipsOperation: class 'dzsave' not found"

This works fine in the notebook:

import pyvips img = pyvips.Image.new_from_file('my_wsi.svs')

This throws an exception:

img.dzsave('my_tiles')

I am using a dockerfile from: https://github.com/jupyter/docker-stacks/blob/main/images/scipy-notebook/Dockerfile My edits in order to add pyvips ("libvips-dev" and "pyvips") are marked with "**" in the docker file text below.


    # Copyright (c) Jupyter Development Team.
    # Distributed under the terms of the Modified BSD License.
    ARG REGISTRY=quay.io
    ARG OWNER=jupyter
    ARG BASE_CONTAINER=$REGISTRY/$OWNER/minimal-notebook
    FROM $BASE_CONTAINER

    LABEL maintainer="Jupyter Project <[email protected]>"

    # Fix: https://github.com/hadolint/hadolint/wiki/DL4006
    # Fix: https://github.com/koalaman/shellcheck/wiki/SC3014

    SHELL ["/bin/bash", "-o", "pipefail", "-c"]

    USER root

    RUN apt-get update --yes && \
        apt-get install --yes --no-install-recommends \
        # for cython: https://cython.readthedocs.io/en/latest/src/quickstart/install.html
        build-essential \
        **libvips-dev \**
        # for latex labels
        cm-super \
        dvipng \
        # for matplotlib anim
        ffmpeg && \
        apt-get clean && rm -rf /var/lib/apt/lists/*

    USER ${NB_UID}

    # Install Python 3 packages
    RUN mamba install --yes \
        'altair' \
        'beautifulsoup4' \
        'bokeh' \
        'bottleneck' \
        'cloudpickle' \
        'conda-forge::blas=*=openblas' \
        'cython' \
        'dask' \
        'dill' \
        'h5py' \
        'ipympl'\
        'ipywidgets' \
        'jupyterlab-git' \
        'matplotlib-base' \
        'numba' \
        'numexpr' \
        'openpyxl' \
        'pandas' \
        'patsy' \
        'protobuf' \
        **'pyvips' \  **  
        'pytables' \    
        'scikit-image' \
        'scikit-learn' \
        'scipy' \
        'seaborn' \
        'sqlalchemy' \
        'statsmodels' \
        'sympy' \
        'widgetsnbextension'\
        'xlrd' && \
        mamba clean --all -f -y && \
        fix-permissions "${CONDA_DIR}" && \
        fix-permissions "/home/${NB_USER}"

    # Install facets package which does not have a `pip` or `conda-forge` package at the moment
    WORKDIR /tmp
    RUN git clone https://github.com/PAIR-code/facets && \
        jupyter nbclassic-extension install facets/facets-dist/ --sys-prefix && \
        rm -rf /tmp/facets && \
        fix-permissions "${CONDA_DIR}" && \
        fix-permissions "/home/${NB_USER}"

    # Import matplotlib the first time to build the font cache
    RUN MPLBACKEND=Agg python -c "import matplotlib.pyplot" && \
        fix-permissions "/home/${NB_USER}"

    USER ${NB_UID}

    WORKDIR "${HOME}"`
1

There are 1 answers

0
jcupitt On BEST ANSWER

You are installing ubuntu's libvips, but then installing pyvips with mamba. They have their own mostly broken libvips binary which is missing dzsave.

I wouldn't use mamba. Systems like this can be useful on windows, where installing the correct binary for a python package is often tricky, but on linux systems it's almost always much safer and more reliable to use the system binaries.

I tried this dockerfile:

FROM quay.io/jupyter/minimal-notebook

USER root

RUN apt-get update -y 
RUN apt-get install -y --no-install-recommends \
        build-essential \
        libvips-dev

RUN pip3 install pyvips

Then ran:

$ docker build -t pyvips-jupyter .
[+] Building 66.0s (7/7) FINISHED                              docker:default
 => [internal] load build definition from Dockerfile                     0.0s
 => => transferring dockerfile: 216B                                     0.0s
 => [internal] load .dockerignore                                        0.1s
 => => transferring context: 2B                                          0.0s
 => [internal] load metadata for quay.io/jupyter/minimal-notebook:lates  0.0s
 => [1/3] FROM quay.io/jupyter/minimal-notebook                          0.4s
 => [2/3] RUN apt-get update -y && apt-get install -y --no-install-rec  58.4s
 => [3/3] RUN pip3 install pyvips                                        3.7s 
 => exporting to image                                                   3.4s 
 => => exporting layers                                                  3.4s 
 => => writing image sha256:09e1adc3b15c8df5a12a940e8d58a628e965d0099e9  0.0s 
 => => naming to docker.io/library/pyvips-jupyter                        0.0s 
$ docker run --rm -it pyvips-jupyter /bin/bash
(base) root@de4112305fa0:~# python3
Python 3.11.7 | packaged by conda-forge | (main, Dec 23 2023, 14:43:09) [GCC 12.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pyvips
>>> pyvips.API_mode
True
>>> x = pyvips.Image.black(10,10)
>>> x.dzsave("y")
>>>