Python Quick Start
GraalVM is not just a Java Virtual Machine to run Java. It is also a high-performance multilingual runtime and provides support for a number of languages beyond Java, allowing different languages and libraries to interoperate with no performance penalty.
Python is one of the supported languages and GraalVM provides the Python 3 runtime environment. The key to GraalVM’s polyglot support is language compliance, and a primary goal of the GraalVM Python runtime is to support SciPy and its constituent libraries, to work with other data science and machine learning libraries from the rich Python ecosystem.
The Python runtime is yet experimental in GraalVM, but it already offers performance 5-6 times faster than CPython 3.8 (after warm-up) or 6-7x faster than Jython. Apart the performance benefits, GraalVM’s Python runtime enables the support for native extensions that Jython never supported, the possibility to create native platform binaries using the Native Image, a managed execution mode to run, for example, NumPy extensions in a safe manner, and many more.
Here you will find information about installing GraalVM and Python support, running Python applications, creating a virtual environment, and adding supported packages. If you have experience using GraalVM’s Python runtime, you can skip this getting started guide and proceed to the in-depth Python reference manual.
To run Python on GraalVM, you need to have GraalVM installed first. Choose the platform and proceed to the installation steps:
The Python runtime is not shipped with the default GraalVM installation package, but can be quickly added using
the updater utility,
gu install python
The Python runtime requires the LLVM toolchain for its operation, and you will be prompted to install this dependency, if not yet installed:
gu install llvm-toolchain
Once Python’s runtime is installed, the
graalpython binary appears in the GRAALVM_HOME/bin/ directory.
Run Python Applications
GraalVM’s Python support targets Python 3.8 compatibility.
The support is still limited at this stage, but you can run simple Python commands or programs with the
graalpython [options] [-c cmd | filename]
If no program file or command is given, you will be dropped into the Python shell and run Python scripts interactively:
graalpython >>> 1 + 2 3 >>> exit()
GraalVM supports some of the same options as Python 3.8 as well as some additional options to control the underlying Python runtime, GraalVM’s tools, and the execution engine. These can be viewed using the following command:
graalpython --help --help:tools --help:languages
Create a Virtual Environment and Install Supported Packages
The recommended way of using GraalVM’s Python runtime is from a virtual environment. Creating a virtual environment prevents any incompatible interaction with the local user’s packages that may have been installed using a system installation of CPython.
- Create the virtual environment with GraalVM:
graalpython -m venv <venv-dir>
- Activate the environment in the shell session:
There are not enough standard libraries to run the standard package installers for many packages with GraalVM Python runtime yet.
As a convenience, GraalVM’s Python runtime provides a tool called
ginstall to install the available packages.
To see the list of installable packages, run:
graalpython -m ginstall install --help
To install the package, provide the name:
graalpython -m ginstall install <package name>
For more information, continue reading to the Installing Supported Packages guide.
What to Read Next
For more extensive user documentation, proceed to the Python reference manual. If you consider GraalVM’s Python runtime as a replacement for Jython, consult the Jython Migration guide. The code base of GraalVM’s Python implementation is available on GitHub.