Skip to content

How to install numpy, PyTorch and pandas under GraalPy+JVM and x64 architecture? (SOLVED) #537

@vak

Description

@vak

Are there clear instruction how to install numpy, PyTorch and pandas under GraalPy+JVM+x64? (RESOLVED, see updete below)
(JVM is important, because a Java class should be called from externally supplied JAR)

I am having hard times to install all three packages in GraalPy+JVM.
I tried different OS distributives (ubuntu:22.04, ghcr.io/graalvm/jdk-community:24) without success.

graalpy -m pip install numpy torch pandas triggers the installation from sources and the compilation from sources triggers CMake and it causes the error:

#7 1314.0       -- Building using own protobuf under third_party per request.
#7 1314.0       -- Use custom protobuf build.
#7 1314.0       CMake Error at third_party/protobuf/cmake/CMakeLists.txt:2 (cmake_minimum_required):
#7 1314.0         Compatibility with CMake < 3.5 has been removed from CMake.
#7 1314.0       
#7 1314.0         Update the VERSION argument <min> value.  Or, use the <min>...<max> syntax
#7 1314.0         to tell CMake that the project requires at least <min> but has been updated
#7 1314.0         to work with policies introduced by <max> or earlier.
#7 1314.0       
#7 1314.0         Or, add -DCMAKE_POLICY_VERSION_MINIMUM=3.5 to try configuring anyway.
#7 1314.0       
#7 1314.0       
#7 1314.0       -- Configuring incomplete, errors occurred!
#7 1314.0       [end of output]
#7 1314.0   

I tried to set
ENV CMAKE_ARGS="-DCMAKE_POLICY_VERSION_MINIMUM=3.5"
ENV CMAKE_POLICY_VERSION_MINIMUM=3.5
but they seem to be "shadowed" by isolated pip build, so i tried graalpy -m pip install --no-build-isolation "cmake<3.20", but met many issues on this path as well.

Also i tried these versions:
graalpy -m pip install numpy==1.23.5 torch==1.13.1
because I know that year ago the image was build successfully for them -- still the same CMake error

Instructions are wellcomed, and a Dockerfile for reproducibility even more wellcomed!
🙏

UPDATE: after many-many hours spent, I finally got the working Docker image!

FROM container-registry.oracle.com/graalvm/jdk:24

# Install dependencies for pyenv, GraalPy, and numpy compilation
RUN microdnf update -y && \
    microdnf install -y \
        curl \
        git \
        gcc \
        gcc-c++ \
        make \
        patch \
        openssl-devel \
        bzip2-devel \
        libffi-devel \
        readline-devel \
        sqlite-devel \
        xz-devel \
        && microdnf clean all

# Download and install GraalPy JVM version manually (pyenv only provides Native version)
ARG GRAALPY_VERSION=24.2.1
ARG PLATFORM=linux-amd64

RUN curl -L "https://github.com/oracle/graalpython/releases/download/graal-$GRAALPY_VERSION/graalpy-jvm-$GRAALPY_VERSION-$PLATFORM.tar.gz" \
    -o /tmp/graalpy-jvm.tar.gz && \
    tar -xzf /tmp/graalpy-jvm.tar.gz -C /opt && \
    rm /tmp/graalpy-jvm.tar.gz && \
    mv /opt/graalpy-$GRAALPY_VERSION-$PLATFORM /opt/graalpy

ENV PATH="/opt/graalpy/bin:$PATH"
ENV GRAALPY_HOME="/opt/graalpy"

RUN graalpy --version && \
    python --version

RUN graalpy -m venv /opt/graalpy-venv

# or pin it to version that worked for me: 1.26.4
RUN /opt/graalpy-venv/bin/pip install --upgrade pip && \
    /opt/graalpy-venv/bin/pip install "numpy<2.0"

RUN microdnf update -y && \
    microdnf install -y cmake && \
    microdnf clean all

RUN microdnf --enablerepo=ol10_codeready_builder install ninja-build

RUN /opt/graalpy-venv/bin/pip install pyyaml
RUN /opt/graalpy-venv/bin/pip install typing_extensions

ENV PIP_NO_BUILD_ISOLATION=1
RUN /opt/graalpy-venv/bin/pip install --upgrade setuptools wheel 
ENV CFLAGS="-Wno-error=maybe-uninitialized -Wno-error=uninitialized" \
    CXXFLAGS="-Wno-error=maybe-uninitialized -Wno-error=uninitialized" \
    CMAKE_ARGS="-DCMAKE_CXX_FLAGS='-Wno-error=maybe-uninitialized -Wno-error=uninitialized' -DCMAKE_C_FLAGS='-Wno-error=maybe-uninitialized -Wno-error=uninitialized'"

RUN /opt/graalpy-venv/bin/pip install --no-build-isolation torch==2.2.1

# install like this or pin it to version 2.2.3 that worked for me:
RUN /opt/graalpy-venv/bin/pip install pandas

ENV PATH="/opt/graalpy-venv/bin:$PATH"

WORKDIR /app
CMD ["python"]

not ideal, but finally works!

bash-5.2# python
Python 3.11.7 (Wed Apr 02 19:53:28 GMT 2025)
[Graal, Oracle GraalVM, Java 24.0.1 (amd64)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy, torch, pandas
>>> numpy.__version__
'1.26.4'
>>> torch.__version__
'2.2.1'
>>> pandas.__version__
'2.2.3'
>>>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions