GraalPy as a CPython Replacement

Choosing the GraalPy Runtime

GraalPy provides a Python 3.10 compliant runtime. A primary goal is to support PyTorch, SciPy, and their constituent libraries, as well as to work with other data science and machine learning libraries from the rich Python ecosystem. GraalPy is distributed as an ahead-of-time compiled native executable, compact in size.

GraalPy provides the following capabilities:

GraalPy Distributions

GraalPy is available as GraalPy built on Oracle GraalVM and GraalPy Community.

Two language runtime options are available for the Oracle and Community distributions of GraalPy:

GraalPy Identification

The four GraalPy runtimes are identified as follows, using the general pattern graalpy(-community)(-jvm)-<version>-<os>-<arch>:

  Oracle Community
Native graalpy-<version>-<os>-<arch> graalpy-community-<version>-<os>-<arch>
JVM graalpy-jvm-<version>-<os>-<arch> graalpy-community-jvm-<version>-<os>-<arch>

Comparison

Runtime Native (default) JVM
Time to start faster slower
Time to reach peak performance faster slower
Peak performance (also considering GC) good best
Java interoperability needs configuration works

Installing GraalPy

Linux

The easiest way to install GraalPy on Linux is to use Pyenv (the Python version manager). To install version 24.0.0 using Pyenv, run the following commands:

pyenv install graalpy-24.0.0
pyenv shell graalpy-24.0.0

Before running pyenv install, you may need to update pyenv to include the latest GraalPy versions.

Alternatively, you can download a compressed GraalPy installation file from GitHub releases.

  1. Find the download that matches the pattern graalpy-XX.Y.Z-linux-amd64.tar.gz or graalpy-XX.Y.Z-linux-aarch64.tar.gz (depending on your platform) and download.
  2. Uncompress the file and update your PATH environment variable to include to the graalpy-XX.Y.Z-linux-amd64/bin (or graalpy-XX.Y.Z-linux-aarch64/bin) directory.

Note: On Oracle Linux 9, additionally install the libxcrypt library that is required for the GraalPy native runtime: yum install libxcrypt-compat.

macOS

The easiest way to install GraalPy on macOS is to use Pyenv (the Python version manager). To install version 24.0.0 using Pyenv, run the following commands:

pyenv install graalpy-24.0.0
pyenv shell graalpy-24.0.0

Before running pyenv install, you may need to update pyenv to include the latest GraalPy versions.

Alternatively, you can download a compressed GraalPy installation file from GitHub releases.

  1. Find the download that matches the pattern graalpy-XX.Y.Z-macos-amd64.tar.gz or graalpy-XX.Y.Z-macos-aarch64.tar.gz (depending on your platform) and download.
  2. Remove the quarantine attribute.
     sudo xattr -r -d com.apple.quarantine /path/to/graalpy
    

    For example:

     sudo xattr -r -d com.apple.quarantine ~/.pyenv/versions/graalpy-24.0.0
    
  3. Uncompress the file and update your PATH environment variable to include to the graalpy-XX.Y.Z-macos-amd64/bin (or graalpy-XX.Y.Z-macos-aarch64/bin) directory.

Windows

  1. Find and download a compressed GraalPy installation file from GitHub releases that matches the pattern graalpy-XX.Y.Z-windows-amd64.tar.gz.
  2. Uncompress the file and update your PATH variable to include to the graalpy-XX.Y.Z-windows-amd64/bin directory.

Windows Limitations

The Windows distribution of GraalPy has more limitations than its Linux or macOS counterpart, so not all features and packages may be available.

It has the following known issues:

Installing Packages

The best way of using GraalPy is from a venv virtual environment. This generates wrapper scripts and makes the implementation usable from a shell as the standard Python interpreter.

  1. Create a virtual environment with GraalPy by running the following command:
     graalpy -m venv <venv-dir>
    

    For example:

     graalpy -m venv ~/.virtualenvs/graalpy-24.0.0
    
  2. Activate the environment in your shell session:
     source <venv-dir>/bin/activate
    

    For example:

     source ~/.virtualenvs/graalpy-24.0.0/bin/activate
    

Multiple executables are available in the virtual environment, including: python, python3, and graalpy.

Note: To deactivate the Python environment (and return to your shell), run deactivate.

The pip package installer is available when using a virtual environment. The GraalPy implementation of pip may choose package versions other than the latest in cases where it ships patches to make these work better.