Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Python on Graviton

Python is an interpreted, high-level, general-purpose programming language, with interpreters available for many operating systems and architectures, including arm64. Read more on Wikipedia

1. Installing Python packages

When pip (the standard package installer for Python) is used, it pulls the packages from Python Package Index and other indexes. To ensure you can install binary packages from Python Package Index, make sure to update your pip installation to version 20.3 or later. pip 19.3 added the manylinux2014 tag, the first manylinux tag for aarch64, and pip 20.3 added the manylinux_x_y tags (PEP 600) that newer wheels use, such as manylinux_2_28.

# To ensure an up-to-date pip version
sudo python3 -m pip install --upgrade pip

AWS is actively working to make pre-compiled packages available for Graviton. You can see a current list of the over 200 popular python packages we track nightly for AL2 and Ubuntu for Graviton support status at our Python wheel tester.

In the case pip could not find a pre-compiled package, it automatically downloads, compiles, and builds the package from source code. Normally it may take a few more minutes to install the package from source code than from pre-built. For some large packages, it may take up to 20 minutes. In some cases, compilation may fail due to missing dependencies. Before trying to build a python package from source, try python3 -m pip install --prefer-binary <package> to attempt to install a wheel that is not the latest version. Sometimes automated package builders will push a release without all the wheels due to failures during a build that will be corrected at a later date. If this is not an option, follow the following instructions to build a python package from source.

1.1 Prerequisites for installing Python packages from source

For installing common Python packages from source code, we need to install the following development tools:

On AmazonLinux2 or RedHat:

sudo yum install "@Development tools" python3-pip python3-devel blas-devel gcc-gfortran lapack-devel
python3 -m pip install --user --upgrade pip

On Debian/Ubuntu:

sudo apt update
sudo apt-get install build-essential python3-pip python3-dev libblas-dev gfortran liblapack-dev
python3 -m pip install --user --upgrade pip

On all distributions, additional compile time dependencies might be needed depending on the Python modules you are trying to install.

When adopting Graviton, it is recommended to use recent software versions as much as possible, and Python is no exception.

Python 2.7 is EOL since January the 1st 2020, it is definitely recommended to upgrade to a Python 3.x version before moving to Graviton.

Python 3.9 reached EOL in October, 2025, so when starting to port an application to Graviton, it is recommended to target at least Python 3.11.

1.3 Python on AL2 and RHEL 8

AL2 and RHEL 8 distribute older Pythons by default: 3.7 and 3.6 respectively. Python 3.6 has been EOL since December, 2021 and Python 3.7 has been EOL since June 2023. Therefore, some package maintainers have already begun dropping support for Python 3.6 and 3.7 by omitting prebuilt wheels published to pypi.org. For some packages, it is still possible to use the default Python by using the distribution from the package manager. For example numpy no longer publishes Python 3.6 wheels, but can be installed from the package manager: yum install python3-numpy.

Another option is to use a newer Python than the default. On RHEL 8.10, you can install Python 3.12 and its pip: yum install python3.12 python3.12-pip. Then use that pip to install the latest versions of packages: python3.12 -m pip install numpy. Python 3.8 and 3.9 are also available on RHEL 8, but their pip packages are older than 20.3, so they do not install wheels tagged manylinux_2_28. On AL2, amazon-linux-extras enable python3.8 exposes Python 3.8 packages. Python 3.8’s pip (21.0.1) supports the manylinux_x_y tags, but AL2’s glibc 2.26 is too old for wheels tagged manylinux_2_28.

Some common Python packages that are distributed by the package manager are:

  1. python3-numpy
  2. python3-markupsafe
  3. python3-pillow

To see a full list run: yum search python3

Python wheel glibc requirements

Some python wheel packages installed with pip require newer libc versions implicitly and will fail to import properly in some cases with a similar error message as below:

ImportError: /lib64/libm.so.6: version `GLIBC_2.27' not found

This can be a problem on distributions such as Amazon Linux 2 that ship with a relatively old glibc (v2.26 in case of Amazon Linux 2). This happens because pip does a simple string match on the wheel filename to determine if a wheel will be compatible with the system. In these cases, it is recommended to first identify if a version of the package is available through the distro’s package manager, install an older version of the package if able, or finally upgrade to a distro that uses a newer glibc – such as AL2023, Ubuntu 20.04, or Ubuntu 22.04.

2. Scientific and numerical application (NumPy, SciPy, BLAS, etc)

Python relies on native code to achieve high performance. For scientific and numerical applications NumPy and SciPy provide an interface to high performance computing libraries such as ATLAS, BLAS, BLIS, OpenBLAS, etc. These libraries contain code tuned for Graviton processors.

It is recommended to use the latest software versions as much as possible. If the latest version migration is not feasible, please ensure that it is at least the minimum version recommended below because multiple fixes related to data precision and correctness on aarch64 went into OpenBLAS between v0.3.9 and v0.3.17 and the below SciPy and NumPy versions upgraded OpenBLAS from v0.3.9 to OpenBLAS v0.3.17.

OpenBLAS: >= v0.3.17 SciPy: >= v1.7.2 NumPy: >= 1.21.1

Both SciPy>=1.5.3 and NumPy>=1.19.0 vend binary wheel packages for Aarch64, but if you need better performance, then compiling the best performance numerical library is an option. To do so, follow the below instructions.

2.1 Install OpenBLAS

OpenBLAS is an optimized BLAS (Basic Linear Algebra Subprograms) library based on GotoBLAS2 1.13 BSD version. The library provides optimized “gemv” and “gemm” routines for Graviton architecture. Binary distribuiton is available for both “pthread” and “openmp” runtime, with “openblas” being the pthread version and “openblas-openmp” the openmp version. Install the appropriate version based on the execution runtime.

2.1.1 Install OpenBLAS on Ubuntu and Debian

# pthread version
sudo apt -y install libopenblas-dev

# openmp version
sudo apt -y install libopenblas-openmp-dev

2.1.2 Install OpenBLAS on AmazonLinux2023 (AL2023) and RedHat

# pthread version
sudo yum -y install openblas

# openmp version
sudo yum -y install openblas-openmp

2.1.3 Install OpenBLAS with Conda

Please refer to the Graviton Support in Conda section to setup conda environment.

# pthread version
conda install -y openblas

# openmp version
conda install -y openblas=*=*openmp*

2.2 BLIS may be a faster BLAS

The default SciPy and NumPy binary installations with pip3 install numpy scipy are configured to use OpenBLAS. The default installations of SciPy and NumPy are easy to setup and well tested.

Some workloads will benefit from using BLIS. Benchmarking SciPy and NumPy workloads with BLIS might allow to identify additional performance improvement.

2.3 Install NumPy and SciPy with BLIS on Ubuntu and Debian

On Ubuntu and Debian apt install python3-numpy python3-scipy will install NumPy and SciPy with BLAS and LAPACK libraries. To install SciPy and NumPy with BLIS and OpenBLAS on Ubuntu and Debian:

sudo apt -y install python3-scipy python3-numpy libopenblas-dev libblis-dev
sudo update-alternatives --set libblas.so.3-aarch64-linux-gnu \
    /usr/lib/aarch64-linux-gnu/blis-openmp/libblas.so.3

To switch between available alternatives:

sudo update-alternatives --config libblas.so.3-aarch64-linux-gnu
sudo update-alternatives --config liblapack.so.3-aarch64-linux-gnu

2.4 Install NumPy and SciPy with BLIS on AmazonLinux2 (AL2) and RedHat

Prerequisites to build SciPy and NumPy with BLIS on arm64 AL2 and RedHat:

# Install AL2/RedHat prerequisites
sudo yum install "@Development tools" python3-pip python3-devel blas-devel gcc-gfortran

# Install BLIS
git clone https://github.com/flame/blis $HOME/blis
cd $HOME/blis;  ./configure --enable-threading=openmp --enable-cblas --prefix=/usr cortexa57
make -j4;  sudo make install

# Install OpenBLAS
git clone https://github.com/xianyi/OpenBLAS.git $HOME/OpenBLAS
cd $HOME/OpenBLAS
make -j4 BINARY=64 FC=gfortran USE_OPENMP=1 NUM_THREADS=64
sudo make PREFIX=/usr install

To build and install NumPy and SciPy with BLIS and OpenBLAS:

git clone https://github.com/numpy/numpy/ $HOME/numpy
cd $HOME/numpy;  pip3 install .

git clone https://github.com/scipy/scipy/ $HOME/scipy
cd $HOME/scipy;  pip3 install .

When NumPy and SciPy detect the presence of the BLIS library at build time, they will use BLIS in priority over the same functionality from BLAS and OpenBLAS. OpenBLAS or LAPACK libraries need to be installed along BLIS to provide LAPACK functionality. To change the library dependencies, one can set environment variables NPY_BLAS_ORDER and NPY_LAPACK_ORDER before building numpy and scipy. The default is: NPY_BLAS_ORDER=mkl,blis,openblas,atlas,accelerate,blas and NPY_LAPACK_ORDER=mkl,openblas,libflame,atlas,accelerate,lapack.

2.5 Testing NumPy and SciPy installation

To test that the installed NumPy and SciPy are built with BLIS and OpenBLAS, the following commands will print native library dependencies:

python3 -c "import numpy as np; np.__config__.show()"
python3 -c "import scipy as sp; sp.__config__.show()"

In the case of Ubuntu and Debian these commands will print blas and lapack which are symbolic links managed by update-alternatives.

2.6 Improving BLIS and OpenBLAS performance with multi-threading

When OpenBLAS is built with USE_OPENMP=1 it will use OpenMP to parallelize the computations. The environment variable OMP_NUM_THREADS can be set to specify the maximum number of threads. If this variable is not set, the default is to use a single thread.

To enable parallelism with BLIS, one needs to both configure with --enable-threading=openmp and set the environment variable BLIS_NUM_THREADS to the number of threads to use, the default is to use a single thread.

2.7 Graviton support in Conda / Miniforge

Conda is a popular package and environment manager for the Python and R programming languages, widely used in scientific computing. Several distributions ship the conda tool. We recommend Miniforge — a minimal conda installer that defaults to the community-maintained, BSD-licensed conda-forge channel, which is free for commercial use. Miniforge avoids the Terms of Service prompt that Anaconda’s main and r channels now require for non-interactive use, which is convenient for unattended provisioning on Graviton instances.

Here is an example on how to use it to install numpy and pandas on aarch64.

The first step is to install conda via Miniforge:

$ wget https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-Linux-aarch64.sh
$ chmod a+x Miniforge3-Linux-aarch64.sh
$ ./Miniforge3-Linux-aarch64.sh

Once installed, you can either use the conda command directly to install packages, or write an environment definition file and create the corresponding environment.

Here’s an example to install numpy and pandas (graviton-example.yml):

name: graviton-example
dependencies:
  - numpy
  - pandas

The next step is to instantiate the environment from that definition:

$ conda env create -f graviton-example.yml

3. Machine Learning Python packages

3.1 PyTorch

pip install numpy
pip install torch torchvision

Please refer to the Graviton PyTorch user guide for optimizing PyTorch inference performance on Graviton.

3.2 TensorFlow

pip install tensorflow

Please refer to the Graviton TensorFlow user guide for the recommended configuration and best practices.

3.3 DGL

Make sure Pytorch is installed, if not, follow Pytorch installation steps

On Ubuntu:

Follow the install from source instructions.

3.4 Sentencepiece

Sentencepiece>=0.1.94 now has pre-compiled binary wheels available for Graviton.

3.5 Morfeusz

On Ubuntu:

# download the source
wget http://download.sgjp.pl/morfeusz/20200913/morfeusz-src-20200913.tar.gz
tar -xf morfeusz-src-20200913.tar.gz
cd Morfeusz/
sudo apt install cmake zip build-essential autotools-dev \
    python3-stdeb python3-pip python3-all-dev python3-pyparsing devscripts \
    libcppunit-dev acl  default-jdk swig python3-all-dev python3-stdeb
export JAVA_TOOL_OPTIONS=-Dfile.encoding=UTF8
mkdir build
cd build
cmake ..
sudo make install
sudo ldconfig -v
sudo PYTHONPATH=/usr/local/lib/python make install-builder

If you run into issue with the last command (make install-builder), please try:

sudo PYTHONPATH=`which python3` make install-builder

4. Other Python packages

confluent_kafka

Since version 2.1.0, confluent-kafka publishes Linux aarch64 wheels on PyPI that include librdkafka. The wheels are tagged manylinux_2_28, so they install with pip 20.3 or later on distributions with glibc 2.28 or later, such as Amazon Linux 2023, Red Hat Enterprise Linux 8, and Ubuntu 20.04 and later (Ubuntu 20.04 ships pip 20.0.2, so upgrade pip there first):

python3 -m pip install confluent-kafka

Each release has aarch64 wheels for a range of Python versions (2.15.1: Python 3.8 to 3.14). On RHEL 8, the default Python 3.6 is too old for current releases, and the pip packages for Python 3.6, 3.8 and 3.9 are older than 20.3, so pip tries to build from source instead. Python 3.12, available from RHEL 8.10, has a new enough pip:

sudo yum install python3.12 python3.12-pip
python3.12 -m pip install confluent-kafka

Amazon Linux 2 has glibc 2.26, so pip cannot use these wheels there. On Amazon Linux 2, first install librdkafka and its development libraries by following the instructions on this page. As part of this process, you will install gcc, pip for Python3, and Python development headers.

Once complete, you can then install the confluent_kafka module directly from source:

python3 -m pip install --user --no-binary confluent-kafka confluent-kafka

open3d

Open3d required glibc version 2.27 or higher. Amazon Linux 2 includes glibc 2.26, which is not sufficient. In order to use open3d, please use Amazon Linux 2023 or later, Ubuntu Bionic (18.04) or later, or another supported distribution. See open3d documentation for more information.

5. Agent Skills for Python Migration

To automate the x86-to-Graviton migration process using an AI coding assistant (Claude Code, Kiro, Cursor, Codex, Windsurf, and others), use the Python x86-to-Graviton Agent Skill. It walks an agent through checking that every pinned dependency publishes an aarch64 wheel for the project’s interpreter, validating native extensions and vendored binaries, fixing Dockerfile platform settings, and validating installs and tests on ARM64. See tools/skills/ for installation instructions.