Segfault from NumPy import after ROOT in PyROOT in Debian Docker image

ROOT Version: 6.20/00
Platform: Debian GNU/Linux 10 (buster) Docker image
Compiler: g++ (Debian 8.3.0-6) 8.3.0
Python version: 3.7.6

Hi. I’m trying to build a minimal Docker image that has ROOT installed in a Debian Linux environment from source with Python 3.7 to do some validation studies using RooFit + RooStats. At the time of writing this, the only ROOT Docker image that has Python 3.7 in it is rootproject/root which is built on Fedora, so I am attempting to build the image myself starting with the python:3.7-slim image. The following Dockerfile is used:

ARG BASE_IMAGE=python:3.7-slim
FROM ${BASE_IMAGE} as base

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

FROM base as builder

ARG ROOT_VERSION=6.20.00

# As this is builder can split up RUNs to make debugging easier
RUN apt-get -qq -y update && \
    apt-get -qq -y install \
      gcc \
      g++ \
      gfortran \
      git \
      wget \
      cmake \
      zlibc \
      libblas3 \
      zlib1g-dev \
      libbz2-dev \
      libx11-dev \
      libxext-dev \
      libxft-dev \
      libxml2-dev \
      libxpm-dev \
      libz-dev && \
    apt-get -y autoclean && \
    apt-get -y autoremove
# c.f. https://root.cern.ch/building-root#options
RUN mkdir code && \
    cd code && \
    wget https://root.cern/download/root_v${ROOT_VERSION}.source.tar.gz && \
    tar xvfz root_v${ROOT_VERSION}.source.tar.gz && \
    mkdir build && \
    cd build && \
    cmake \
      -Dcxx14=ON \
      -Dtmva=OFF \
      -Dpython=ON \
      -DPYTHON_EXECUTABLE=$(which python3) \
      -DCMAKE_INSTALL_PREFIX=/usr/local \
      ../root-${ROOT_VERSION} && \
    cmake --build . -- -j$(($(nproc) - 1)) && \
    cmake --build . --target install

FROM base
RUN apt-get -qq -y update && \
    apt-get -qq -y install \
      gcc \
      g++ \
      zlibc \
      libblas3 \
      zlib1g-dev \
      libbz2-dev \
      libx11-dev \
      libxext-dev \
      libxft-dev \
      libxml2-dev \
      libxpm-dev \
      libz-dev && \
    apt-get -y autoclean && \
    apt-get -y autoremove
# Use C.UTF-8 locale to avoid issues with ASCII encoding
ENV LC_ALL=C.UTF-8
ENV LANG=C.UTF-8
ENV PYTHONPATH=/usr/local/lib:$PYTHONPATH
ENV LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH
COPY --from=builder /usr/local/bin /usr/local/bin
COPY --from=builder /usr/local/lib /usr/local/lib
COPY --from=builder /usr/local/include /usr/local/include
COPY --from=builder /usr/local/share /usr/local/share
COPY --from=builder /usr/local/etc /usr/local/etc

WORKDIR /home/data
ENV HOME /home

ENTRYPOINT ["/bin/bash"]

So far so good (though if I really just need RooFit + RooStats suggestions for what to turn OFF would be very welcome!), but the problem comes when I try to use it. If I build the Docker image with

docker build . \
  -f Dockerfile \
  --build-arg BASE_IMAGE=python:3.7-slim \
  --build-arg ROOT_VERSION=6.20.00 \
  --tag test-build:latest

then the following will run fine as expected

docker run \
  --rm \
  test-build:latest \
  -c "python -m pip install numpy; python -c 'import numpy as np; import ROOT; print(np.arange(10))'"

but switching the import order of ROOT and NumPy causes a segfault

docker run \
  --rm \
  test-build:latest \
  -c "python -m pip install numpy; python -c 'import ROOT; import numpy as np'"

running this in the REPL gives

root@9437c1dfe296:~/data# python
Python 3.7.6 (default, Feb 26 2020, 15:44:31) 
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import ROOT
>>> import numpy

 *** Break *** segmentation violation
 Generating stack trace...
 0x00007f87c40207d1 in PyErr_SetString at /usr/src/python/Python/errors.c:170 from /usr/local/lib/libpython3.7m.so.1.0
 0x00007f8795f2fc7b in <unknown> from /usr/local/lib/python3.7/lib-dynload/_hashlib.cpython-37m-x86_64-linux-gnu.so
 0x00007f8795f2f4ef in <unknown> from /usr/local/lib/python3.7/lib-dynload/_hashlib.cpython-37m-x86_64-linux-gnu.so
 0x00007f87c3f9d5a3 in _PyMethodDef_RawFastCallKeywords at /usr/src/python/Objects/call.c:719 from /usr/local/lib/libpython3.7m.so.1.0
 0x00007f87c3f9d410 in _PyCFunction_FastCallKeywords at /usr/src/python/Objects/call.c:737 (discriminator 4) from /usr/local/lib/libpython3.7m.so.1.0
 0x00007f87c40124e3 in _PyEval_EvalFrameDefault at /usr/src/python/Python/ceval.c:4568 from /usr/local/lib/libpython3.7m.so.1.0
 0x00007f87c3f9e52a in _PyFunction_FastCallKeywords at /usr/src/python/Objects/call.c:285 from /usr/local/lib/libpython3.7m.so.1.0
 0x00007f87c400ee31 in _PyEval_EvalFrameDefault at /usr/src/python/Python/ceval.c:4621 from /usr/local/lib/libpython3.7m.so.1.0
 0x00007f87c400daa1 in _PyEval_EvalCodeWithName at /usr/src/python/Python/ceval.c:3930 from /usr/local/lib/libpython3.7m.so.1.0
 0x00007f87c400d7a9 in PyEval_EvalCodeEx at /usr/src/python/Python/ceval.c:3966 (discriminator 4) from /usr/local/lib/libpython3.7m.so.1.0
 0x00007f87c400d76b in PyEval_EvalCode at /usr/src/python/Python/ceval.c:530 from /usr/local/lib/libpython3.7m.so.1.0
 0x00007f87c4086dd4 in <unknown> from /usr/local/lib/libpython3.7m.so.1.0
 0x00007f87c3f9dc75 in _PyMethodDef_RawFastCallDict at /usr/src/python/Objects/call.c:531 from /usr/local/lib/libpython3.7m.so.1.0
 0x00007f87c3f9d960 in _PyCFunction_FastCallDict at /usr/src/python/Objects/call.c:589 (discriminator 4) from /usr/local/lib/libpython3.7m.so.1.0
 0x00007f87c4013899 in _PyEval_EvalFrameDefault at /usr/src/python/Python/ceval.c:4641 from /usr/local/lib/libpython3.7m.so.1.0
 0x00007f87c400daa1 in _PyEval_EvalCodeWithName at /usr/src/python/Python/ceval.c:3930 from /usr/local/lib/libpython3.7m.so.1.0
 0x00007f87c3f9e5d2 in _PyFunction_FastCallKeywords at /usr/src/python/Objects/call.c:433 (discriminator 4) from /usr/local/lib/libpython3.7m.so.1.0
 0x00007f87c4012642 in _PyEval_EvalFrameDefault at /usr/src/python/Python/ceval.c:4621 from /usr/local/lib/libpython3.7m.so.1.0
 0x00007f87c3f9e52a in _PyFunction_FastCallKeywords at /usr/src/python/Objects/call.c:285 from /usr/local/lib/libpython3.7m.so.1.0
 0x00007f87c400ec12 in _PyEval_EvalFrameDefault at /usr/src/python/Python/ceval.c:4621 from /usr/local/lib/libpython3.7m.so.1.0
 0x00007f87c3f9e52a in _PyFunction_FastCallKeywords at /usr/src/python/Objects/call.c:285 from /usr/local/lib/libpython3.7m.so.1.0
 0x00007f87c400ee31 in _PyEval_EvalFrameDefault at /usr/src/python/Python/ceval.c:4621 from /usr/local/lib/libpython3.7m.so.1.0
 0x00007f87c3f9e52a in _PyFunction_FastCallKeywords at /usr/src/python/Objects/call.c:285 from /usr/local/lib/libpython3.7m.so.1.0
 0x00007f87c400ee31 in _PyEval_EvalFrameDefault at /usr/src/python/Python/ceval.c:4621 from /usr/local/lib/libpython3.7m.so.1.0
 0x00007f87c3f9ec9a in _PyFunction_FastCallDict at /usr/src/python/Objects/call.c:285 from /usr/local/lib/libpython3.7m.so.1.0
 0x00007f87c3f9e20d in <unknown> from /usr/local/lib/libpython3.7m.so.1.0
 0x00007f87c3f9f9db in _PyObject_CallMethodIdObjArgs at /usr/src/python/Objects/call.c:1255 from /usr/local/lib/libpython3.7m.so.1.0
 0x00007f87c40287d1 in PyImport_ImportModuleLevelObject at /usr/src/python/Python/import.c:1648 from /usr/local/lib/libpython3.7m.so.1.0
 0x00007f87c400c698 in <unknown> from /usr/local/lib/libpython3.7m.so.1.0
 0x00007f87c3f9f585 in PyCFunction_Call at /usr/src/python/Objects/call.c:759 from /usr/local/lib/libpython3.7m.so.1.0
 0x00007f87c4013899 in _PyEval_EvalFrameDefault at /usr/src/python/Python/ceval.c:4641 from /usr/local/lib/libpython3.7m.so.1.0
 0x00007f87c400daa1 in _PyEval_EvalCodeWithName at /usr/src/python/Python/ceval.c:3930 from /usr/local/lib/libpython3.7m.so.1.0
 0x00007f87c3f9ed34 in _PyFunction_FastCallDict at /usr/src/python/Objects/call.c:376 from /usr/local/lib/libpython3.7m.so.1.0
 0x00007f87c3f427ca in <unknown> from /usr/local/lib/libpython3.7m.so.1.0
 0x00007f87c400daa1 in _PyEval_EvalCodeWithName at /usr/src/python/Python/ceval.c:3930 from /usr/local/lib/libpython3.7m.so.1.0
 0x00007f87c400d7a9 in PyEval_EvalCodeEx at /usr/src/python/Python/ceval.c:3966 (discriminator 4) from /usr/local/lib/libpython3.7m.so.1.0
 0x00007f87c400d76b in PyEval_EvalCode at /usr/src/python/Python/ceval.c:530 from /usr/local/lib/libpython3.7m.so.1.0
 0x00007f87c4086dd4 in <unknown> from /usr/local/lib/libpython3.7m.so.1.0
 0x00007f87c3f9dc75 in _PyMethodDef_RawFastCallDict at /usr/src/python/Objects/call.c:531 from /usr/local/lib/libpython3.7m.so.1.0
 0x00007f87c3f9d960 in _PyCFunction_FastCallDict at /usr/src/python/Objects/call.c:589 (discriminator 4) from /usr/local/lib/libpython3.7m.so.1.0
 0x00007f87c4013899 in _PyEval_EvalFrameDefault at /usr/src/python/Python/ceval.c:4641 from /usr/local/lib/libpython3.7m.so.1.0
 0x00007f87c400daa1 in _PyEval_EvalCodeWithName at /usr/src/python/Python/ceval.c:3930 from /usr/local/lib/libpython3.7m.so.1.0
 0x00007f87c3f9e5d2 in _PyFunction_FastCallKeywords at /usr/src/python/Objects/call.c:433 (discriminator 4) from /usr/local/lib/libpython3.7m.so.1.0
 0x00007f87c4012642 in _PyEval_EvalFrameDefault at /usr/src/python/Python/ceval.c:4621 from /usr/local/lib/libpython3.7m.so.1.0
 0x00007f87c3f9e52a in _PyFunction_FastCallKeywords at /usr/src/python/Objects/call.c:285 from /usr/local/lib/libpython3.7m.so.1.0
 0x00007f87c400ec12 in _PyEval_EvalFrameDefault at /usr/src/python/Python/ceval.c:4621 from /usr/local/lib/libpython3.7m.so.1.0
 0x00007f87c3f9e52a in _PyFunction_FastCallKeywords at /usr/src/python/Objects/call.c:285 from /usr/local/lib/libpython3.7m.so.1.0
 0x00007f87c400ee31 in _PyEval_EvalFrameDefault at /usr/src/python/Python/ceval.c:4621 from /usr/local/lib/libpython3.7m.so.1.0
 0x00007f87c3f9e52a in _PyFunction_FastCallKeywords at /usr/src/python/Objects/call.c:285 from /usr/local/lib/libpython3.7m.so.1.0
 0x00007f87c400ee31 in _PyEval_EvalFrameDefault at /usr/src/python/Python/ceval.c:4621 from /usr/local/lib/libpython3.7m.so.1.0
 0x00007f87c3f9ec9a in _PyFunction_FastCallDict at /usr/src/python/Objects/call.c:285 from /usr/local/lib/libpython3.7m.so.1.0
 0x00007f87c3f9e20d in <unknown> from /usr/local/lib/libpython3.7m.so.1.0
 0x00007f87c3f9f9db in _PyObject_CallMethodIdObjArgs at /usr/src/python/Objects/call.c:1255 from /usr/local/lib/libpython3.7m.so.1.0
 0x00007f87c40287d1 in PyImport_ImportModuleLevelObject at /usr/src/python/Python/import.c:1648 from /usr/local/lib/libpython3.7m.so.1.0
 0x00007f87c400c698 in <unknown> from /usr/local/lib/libpython3.7m.so.1.0
 0x00007f87c3f9f585 in PyCFunction_Call at /usr/src/python/Objects/call.c:759 from /usr/local/lib/libpython3.7m.so.1.0
 0x00007f87c4013899 in _PyEval_EvalFrameDefault at /usr/src/python/Python/ceval.c:4641 from /usr/local/lib/libpython3.7m.so.1.0
 0x00007f87c400daa1 in _PyEval_EvalCodeWithName at /usr/src/python/Python/ceval.c:3930 from /usr/local/lib/libpython3.7m.so.1.0
 0x00007f87c3f9ed34 in _PyFunction_FastCallDict at /usr/src/python/Objects/call.c:376 from /usr/local/lib/libpython3.7m.so.1.0
 0x00007f87c3f427ca in <unknown> from /usr/local/lib/libpython3.7m.so.1.0
 0x00007f87c400daa1 in _PyEval_EvalCodeWithName at /usr/src/python/Python/ceval.c:3930 from /usr/local/lib/libpython3.7m.so.1.0
 0x00007f87c400d7a9 in PyEval_EvalCodeEx at /usr/src/python/Python/ceval.c:3966 (discriminator 4) from /usr/local/lib/libpython3.7m.so.1.0
 0x00007f87c400d76b in PyEval_EvalCode at /usr/src/python/Python/ceval.c:530 from /usr/local/lib/libpython3.7m.so.1.0
 0x00007f87c4086dd4 in <unknown> from /usr/local/lib/libpython3.7m.so.1.0
 0x00007f87c3f9dc75 in _PyMethodDef_RawFastCallDict at /usr/src/python/Objects/call.c:531 from /usr/local/lib/libpython3.7m.so.1.0
 0x00007f87c3f9d960 in _PyCFunction_FastCallDict at /usr/src/python/Objects/call.c:589 (discriminator 4) from /usr/local/lib/libpython3.7m.so.1.0
 0x00007f87c4013899 in _PyEval_EvalFrameDefault at /usr/src/python/Python/ceval.c:4641 from /usr/local/lib/libpython3.7m.so.1.0
 0x00007f87c400daa1 in _PyEval_EvalCodeWithName at /usr/src/python/Python/ceval.c:3930 from /usr/local/lib/libpython3.7m.so.1.0
 0x00007f87c3f9e5d2 in _PyFunction_FastCallKeywords at /usr/src/python/Objects/call.c:433 (discriminator 4) from /usr/local/lib/libpython3.7m.so.1.0
 0x00007f87c4012642 in _PyEval_EvalFrameDefault at /usr/src/python/Python/ceval.c:4621 from /usr/local/lib/libpython3.7m.so.1.0
 0x00007f87c3f9e52a in _PyFunction_FastCallKeywords at /usr/src/python/Objects/call.c:285 from /usr/local/lib/libpython3.7m.so.1.0
 0x00007f87c400ec12 in _PyEval_EvalFrameDefault at /usr/src/python/Python/ceval.c:4621 from /usr/local/lib/libpython3.7m.so.1.0
 0x00007f87c3f9e52a in _PyFunction_FastCallKeywords at /usr/src/python/Objects/call.c:285 from /usr/local/lib/libpython3.7m.so.1.0
 0x00007f87c400ee31 in _PyEval_EvalFrameDefault at /usr/src/python/Python/ceval.c:4621 from /usr/local/lib/libpython3.7m.so.1.0
 0x00007f87c3f9e52a in _PyFunction_FastCallKeywords at /usr/src/python/Objects/call.c:285 from /usr/local/lib/libpython3.7m.so.1.0
 0x00007f87c400ee31 in _PyEval_EvalFrameDefault at /usr/src/python/Python/ceval.c:4621 from /usr/local/lib/libpython3.7m.so.1.0
 0x00007f87c3f9ec9a in _PyFunction_FastCallDict at /usr/src/python/Objects/call.c:285 from /usr/local/lib/libpython3.7m.so.1.0
 0x00007f87c3f9e20d in <unknown> from /usr/local/lib/libpython3.7m.so.1.0
 0x00007f87c3f9f9db in _PyObject_CallMethodIdObjArgs at /usr/src/python/Objects/call.c:1255 from /usr/local/lib/libpython3.7m.so.1.0
 0x00007f87c40287d1 in PyImport_ImportModuleLevelObject at /usr/src/python/Python/import.c:1648 from /usr/local/lib/libpython3.7m.so.1.0
 0x00007f879618b795 in <unknown> from /usr/local/lib/python3.7/site-packages/numpy/random/_bit_generator.cpython-37m-x86_64-linux-gnu.so
 0x00007f8796187aad in <unknown> from /usr/local/lib/python3.7/site-packages/numpy/random/_bit_generator.cpython-37m-x86_64-linux-gnu.so
 0x00007f87c406a7f3 in PyModule_ExecDef at /usr/src/python/Objects/moduleobject.c:415 from /usr/local/lib/libpython3.7m.so.1.0
 0x00007f87c408c48c in <unknown> from /usr/local/lib/libpython3.7m.so.1.0
 0x00007f87c3f9dc90 in _PyMethodDef_RawFastCallDict at /usr/src/python/Objects/call.c:498 from /usr/local/lib/libpython3.7m.so.1.0
 0x00007f87c3f9d960 in _PyCFunction_FastCallDict at /usr/src/python/Objects/call.c:589 (discriminator 4) from /usr/local/lib/libpython3.7m.so.1.0
 0x00007f87c4013899 in _PyEval_EvalFrameDefault at /usr/src/python/Python/ceval.c:4641 from /usr/local/lib/libpython3.7m.so.1.0
 0x00007f87c400daa1 in _PyEval_EvalCodeWithName at /usr/src/python/Python/ceval.c:3930 from /usr/local/lib/libpython3.7m.so.1.0
 0x00007f87c3f9e5d2 in _PyFunction_FastCallKeywords at /usr/src/python/Objects/call.c:433 (discriminator 4) from /usr/local/lib/libpython3.7m.so.1.0
 0x00007f87c4012642 in _PyEval_EvalFrameDefault at /usr/src/python/Python/ceval.c:4621 from /usr/local/lib/libpython3.7m.so.1.0
 0x00007f87c3f9e52a in _PyFunction_FastCallKeywords at /usr/src/python/Objects/call.c:285 from /usr/local/lib/libpython3.7m.so.1.0
 0x00007f87c400ec12 in _PyEval_EvalFrameDefault at /usr/src/python/Python/ceval.c:4621 from /usr/local/lib/libpython3.7m.so.1.0
 0x00007f87c3f9e52a in _PyFunction_FastCallKeywords at /usr/src/python/Objects/call.c:285 from /usr/local/lib/libpython3.7m.so.1.0
 0x00007f87c400ee31 in _PyEval_EvalFrameDefault at /usr/src/python/Python/ceval.c:4621 from /usr/local/lib/libpython3.7m.so.1.0
 0x00007f87c3f9e52a in _PyFunction_FastCallKeywords at /usr/src/python/Objects/call.c:285 from /usr/local/lib/libpython3.7m.so.1.0
 0x00007f87c400ee31 in _PyEval_EvalFrameDefault at /usr/src/python/Python/ceval.c:4621 from /usr/local/lib/libpython3.7m.so.1.0
 0x00007f87c3f9ec9a in _PyFunction_FastCallDict at /usr/src/python/Objects/call.c:285 from /usr/local/lib/libpython3.7m.so.1.0
 0x00007f87c3f9e20d in <unknown> from /usr/local/lib/libpython3.7m.so.1.0
 0x00007f87c3f9f9db in _PyObject_CallMethodIdObjArgs at /usr/src/python/Objects/call.c:1255 from /usr/local/lib/libpython3.7m.so.1.0
 0x00007f87c40287d1 in PyImport_ImportModuleLevelObject at /usr/src/python/Python/import.c:1648 from /usr/local/lib/libpython3.7m.so.1.0
 0x00007f87c400c698 in <unknown> from /usr/local/lib/libpython3.7m.so.1.0
 0x00007f87c3f9f585 in PyCFunction_Call at /usr/src/python/Objects/call.c:759 from /usr/local/lib/libpython3.7m.so.1.0
 0x00007f87c4013899 in _PyEval_EvalFrameDefault at /usr/src/python/Python/ceval.c:4641 from /usr/local/lib/libpython3.7m.so.1.0
 0x00007f87c400daa1 in _PyEval_EvalCodeWithName at /usr/src/python/Python/ceval.c:3930 from /usr/local/lib/libpython3.7m.so.1.0
 0x00007f87c3f9ed34 in _PyFunction_FastCallDict at /usr/src/python/Objects/call.c:376 from /usr/local/lib/libpython3.7m.so.1.0
 0x00007f87c3f9f745 in PyObject_CallFunction at /usr/src/python/Objects/call.c:964 from /usr/local/lib/libpython3.7m.so.1.0
 0x00007f87c40281fa in PyImport_Import at /usr/src/python/Python/import.c:1950 from /usr/local/lib/libpython3.7m.so.1.0
 0x00007f87c408c61e in PyImport_ImportModule at /usr/src/python/Python/import.c:1390 from /usr/local/lib/libpython3.7m.so.1.0
 0x00007f87963bba58 in <unknown> from /usr/local/lib/python3.7/site-packages/numpy/random/mtrand.cpython-37m-x86_64-linux-gnu.so
 0x00007f87c406a7f3 in PyModule_ExecDef at /usr/src/python/Objects/moduleobject.c:415 from /usr/local/lib/libpython3.7m.so.1.0
 0x00007f87c408c48c in <unknown> from /usr/local/lib/libpython3.7m.so.1.0
 0x00007f87c3f9dc90 in _PyMethodDef_RawFastCallDict at /usr/src/python/Objects/call.c:498 from /usr/local/lib/libpython3.7m.so.1.0
 0x00007f87c3f9d960 in _PyCFunction_FastCallDict at /usr/src/python/Objects/call.c:589 (discriminator 4) from /usr/local/lib/libpython3.7m.so.1.0
 0x00007f87c4013899 in _PyEval_EvalFrameDefault at /usr/src/python/Python/ceval.c:4641 from /usr/local/lib/libpython3.7m.so.1.0
 0x00007f87c400daa1 in _PyEval_EvalCodeWithName at /usr/src/python/Python/ceval.c:3930 from /usr/local/lib/libpython3.7m.so.1.0
 0x00007f87c3f9e5d2 in _PyFunction_FastCallKeywords at /usr/src/python/Objects/call.c:433 (discriminator 4) from /usr/local/lib/libpython3.7m.so.1.0
 0x00007f87c4012642 in _PyEval_EvalFrameDefault at /usr/src/python/Python/ceval.c:4621 from /usr/local/lib/libpython3.7m.so.1.0
 0x00007f87c3f9e52a in _PyFunction_FastCallKeywords at /usr/src/python/Objects/call.c:285 from /usr/local/lib/libpython3.7m.so.1.0
 0x00007f87c400ec12 in _PyEval_EvalFrameDefault at /usr/src/python/Python/ceval.c:4621 from /usr/local/lib/libpython3.7m.so.1.0
 0x00007f87c3f9e52a in _PyFunction_FastCallKeywords at /usr/src/python/Objects/call.c:285 from /usr/local/lib/libpython3.7m.so.1.0
 0x00007f87c400ee31 in _PyEval_EvalFrameDefault at /usr/src/python/Python/ceval.c:4621 from /usr/local/lib/libpython3.7m.so.1.0
 0x00007f87c3f9e52a in _PyFunction_FastCallKeywords at /usr/src/python/Objects/call.c:285 from /usr/local/lib/libpython3.7m.so.1.0
 0x00007f87c400ee31 in _PyEval_EvalFrameDefault at /usr/src/python/Python/ceval.c:4621 from /usr/local/lib/libpython3.7m.so.1.0
  • Why is this happening?
  • Why does the import order matter?
  • What can be done in the build to fix this?
  • If I only care about RooFit + RooStats for this image how can I slim down the image more (turn off more of the build)?

Hello,
From the stack trace I can’t really tell what is going on and I am not aware of any incompatibility between ROOT and numpy.

I understand using Debian for you is a requirement?

From the stack trace I can’t really tell what is going on

Yeah, I agree that it is incomprehensible, but I decided to post it in the event that anyone asked for it.

I understand using Debian for you is a requirement?

Debian itself isn’t a hard requirement, but using an officially supported Docker image that offers the version of Python 3 we want (and is designed to be as small as possible without going to an Alpine based image) is — it just so happens that the PSF chooses to use Debian here and as we’d like to build off of this for testing Python libraries with ROOT it is more useful to build ROOT against the base image’s Python 3 than to try and fight between build differences in the Python runtime between smaller images and the official ROOT images that support Python 3.

The other confusing thing is just what is even wrong here? Something goes wrong, but it isn’t clear what or why.

Looking at the Docker image for ROOT that is build on Fedora with Python 3 it shows that a version of NumPy is packaged with it (we explicitly do not want that as we want to be able to control the NumPy version for testing, which means no TMVA for our ROOT build but that is okay with us) that works fine

$ docker run --rm -it rootproject/root:latest /bin/bash
[root@e2b22025849b /]# python
Python 3.7.6 (default, Jan 30 2020, 09:44:41) 
[GCC 9.2.1 20190827 (Red Hat 9.2.1-1)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import ROOT
>>> import numpy
>>> print(numpy.version.full_version)
1.17.4
>>> 

So I guess it will be worth looking into if this happens with all ROOT versions as well.

Hi,

I built the image and I can reproduce the error. I could narrow it down to just doing

import libPyROOT
import numpy

libPyROOT is a library which is also a C extension module used by PyROOT from Python. I still don’t see why importing this extension module causes a crash when importing numpy.

One thing to try is to install numpy before ROOT is built. When buillding, ROOT looks for numpy.

I built the image and I can reproduce the error

Thanks very much for taking the time to do so. I appreciate that you’re willing to help check this. :+1:

libPyROOT is a library which is also a C extension module used by PyROOT from Python.

Interesting. I’m not sure what to make of this.

One thing to try is to install numpy before ROOT is built. When buillding, ROOT looks for numpy.

Yes, as I knew from previous experience that it looks for NumPy so it can use it in TMVA (maybe other things? I don’t know) this was one of the first things I checked. I still got the error.

I’m checking now if this also happens with the PyROOT we have in master, which is a new one. I will report when I have news.

If the issue is not there in master, would it be an option for you to use it?

If the issue is not there in master, would it be an option for you to use it?

I would be quite happy to do so. I just grabbed the latest stable release as that seemed to be the most robust thing to do.

I can also reproduce the issue with ROOT master using the Debian image, so no luck.

Just so you are unblocked until we find the issue, can you work with the Fedora image in the meantime, installing your own version of numpy?

I can also reproduce the issue with ROOT master using the Debian image

Good to know. Thank you for checking.

can you work with the Fedora image in the meantime

Chris Burr has given me some pointers on getting conda-forge build of ROOT Docker image that should work for the time being (though it is way bigger then what I’m shooting for here).

So, I’m not sure why (I’m thinking some underlying dependencies in packages.txt were missing?) but the following build works:

In a directory with the following:

$ tree
.
├── Dockerfile
└── packages.txt

0 directories, 2 files

where packages.txt contains

# packages.txt
git
dpkg-dev
cmake
g++
gcc
binutils
libx11-dev
libxpm-dev
libxft-dev
libxext-dev
gfortran
libssl-dev
libpcre3-dev
xlibmesa-glu-dev
libglew1.5-dev
libftgl-dev
libfftw3-dev
libcfitsio-dev
graphviz-dev
libavahi-compat-libdnssd-dev
libldap2-dev
python3-dev
libxml2-dev
libkrb5-dev
libgsl0-dev
libqt4-dev
locales
ccache
wget
fonts-freefont-otf

and the Dockerfile is

ARG BASE_IMAGE=python:3.7-slim
FROM ${BASE_IMAGE} as base

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

FROM base as builder

ARG ROOT_VERSION=6-20-00

# As this is builder can split up RUNs to make debugging easier
COPY packages.txt packages.txt
RUN apt-get -qq -y update && \
    apt-get -qq -y install $(cat packages.txt) && \
    apt-get -y autoclean && \
    apt-get -y autoremove && \
    rm -rf /var/lib/apt-get/lists/*
# c.f. https://root.cern.ch/building-root#options
RUN mkdir code && \
    cd code && \
    git clone --depth 5 https://github.com/root-project/root \
      --branch "v${ROOT_VERSION}" \
      --single-branch \
      "root-${ROOT_VERSION}" && \
    mkdir build && \
    cd build && \
    cmake \
      -Dall=OFF \
      -Dcxx14=ON \
      -Dpython=ON \
      -DPYTHON_EXECUTABLE=$(which python3) \
      -DCMAKE_INSTALL_PREFIX=/usr/local \
      ../root-${ROOT_VERSION} && \
    cmake --build . -- -j$(($(nproc) - 1)) && \
    cmake --build . --target install

FROM base
RUN apt-get -qq -y update && \
    apt-get -qq -y install \
      gcc \
      g++ \
      zlibc \
      libblas3 \
      zlib1g-dev \
      libbz2-dev \
      libx11-dev \
      libxext-dev \
      libxft-dev \
      libxml2-dev \
      libxpm-dev \
      libz-dev && \
    apt-get -y autoclean && \
    apt-get -y autoremove && \
    rm -rf /var/lib/apt-get/lists/*
# Use C.UTF-8 locale to avoid issues with ASCII encoding
ENV LC_ALL=C.UTF-8
ENV LANG=C.UTF-8
ENV PYTHONPATH=/usr/local/lib:$PYTHONPATH
ENV LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH
COPY --from=builder /usr/local/bin /usr/local/bin
COPY --from=builder /usr/local/lib /usr/local/lib
COPY --from=builder /usr/local/include /usr/local/include
COPY --from=builder /usr/local/share /usr/local/share
COPY --from=builder /usr/local/etc /usr/local/etc
COPY --from=builder /usr/local/fonts /usr/local/fonts

WORKDIR /home/data
ENV HOME /home

ENTRYPOINT ["/bin/bash"]

the following build works

docker build . \
  -f Dockerfile \
  --build-arg BASE_IMAGE=python:3.7-slim \
  --build-arg ROOT_VERSION=6.20.00 \
  --tag test-build:latest

and the following import order works just fine

docker run \
  --rm \
  test-build:latest \
  -c "python -m pip install numpy; python -c 'import ROOT; import numpy as np; print(np.arange(10))'"

So not much to say, other than this works and sorry for the noise, but thank you for taking time to debug this.

Hi,

Thank you for reporting back with the solution, I’m glad you can continue with the validation studies, let us know if we can help you with anything else.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.