- Latest (GraalVM for JDK 21)
- Dev Build
- GraalVM for JDK 21
- GraalVM for JDK 20
- GraalVM for JDK 17
- GraalVM 22.3
- GraalVM 22.2
- GraalVM 22.1
- GraalVM 22.0
- GraalVM 21.3
- Java Reference
- Java on Truffle
- LLVM Languages Reference
- Python Reference
- Installing Supported Packages
- Operating System Interfaces
- Python Code Parsing and pyc Files
- Jython Compatibility
- Tooling Support for Python
- Ruby Reference
- R Reference
- WebAssembly Reference
GraalVM Python Runtime
GraalVM provides a Python 3.8 compliant runtime. A primary goal of the GraalVM Python runtime is to support SciPy and its constituent libraries, as well as to work with other data science and machine learning libraries from the rich Python ecosystem. At this point, the Python runtime is made available for experimentation and curious end-users. See FAQ for commonly asked questions about this implementation.
Installing Python #
The Python runtime is not provided by default, and can be added to GraalVM with the GraalVM Updater,
gu install python
The above command will install Python from the catalog.
Running Python #
GraalVM’s Python support targets Python 3.8 compatibility.
While the support is still limited, you can run simple Python commands or programs with the
graalpy [options] [-c cmd | filename]
If no program file or command is given, you are dropped into a simple REPL.
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:
graalpy --help --help:tools --help:languages
Installing Supported Packages #
GraalVM Python runtime comes with a tool called
ginstall which may be used to install a small list of packages known to work to some extent with GraalVM’s Python runtime.
It is recommended to always create a virtual environment first, using the standard Python module
Creating such an environment avoids any incompatible interaction with the local user’s packages that may have been
installed using a system installation of CPython:
graalpy -m venv my_new_venv source my_new_venv/bin/activate
To see the list of installable packages, run:
graalpy -m ginstall install --help
This will print a short help document including a comma-separated list of packages you can install. The installation works as described in that help document:
graalpy -m ginstall install pandas
Note that when calling Python from Java, the polyglot shell, or another language on GraalVM, you should always evaluate the piece of Python code first to make installed packages available:
For more information, continue reading to the Installing Supported Packages guide.
Native Image and JVM Runtime #
By default, GraalVM runs Python from a binary, compiled ahead-of-time with Native Image, yielding faster startup time and lower footprint.
Although the ahead-of-time compiled binary includes the Python and LLVM interpreters, in order to interoperate with
other languages you have to supply the
This instructs the launcher to run on the JVM instead of in Native Image mode.
Thus, you will notice a longer startup time.