PyTorch - Q-engineering
Go to content
PyTorch on Raspberry Pi 5

Install PyTorch on a Raspberry Pi 5.

Last updated: Februari 24, 2024


This page will guide you through the installation of PyTorch on a Raspberry Pi 5 with a Bookworm 64-bit operating system.

PyTorch is a software library specially developed for deep learning. It consumes a lot of resources of your Pi. You can run PyTorch on a Raspberry Pi 5, but don't expect miracles. It runs your models, if not too complicated, but it can't train new models. Nor can it perform so-called transfer learning.

PyTorch runs on Python. If you want your PyTorch models to run fast on your Raspberry Pi, consider exporting your model to ONNX. Once saved as an ONNX model, you can import it into an ARM-friendly C++ framework such as ncnn or MNN. It will speed up your model considerably.

Version check.
Please check your operating system before installing ncnn on your Raspberry Pi 4. Run the command getconf LONG_BIT and verify your version.

Version check

Installation by wheel.

In the early days, PyTorch did not support the Raspberry Pi or any other aarch64 operating system.
Fortunately, these days are over. Now you can install Pytorch, TochVision and TochAudio with one command.

Before proceeding, you need a virtual environment in which PyTorch and its libraries are installed.
Please take a look at our Bookworm page, where you can find everything you need to know about virtual environments.

Once you have activated your virtual environment, you can install PyTorch with the following command.
# get a fresh start
$ sudo apt-get update
$ sudo apt-get upgrade
# install the dependencies
$ sudo apt-get install python3-pip libjpeg-dev libopenblas-dev libopenmpi-dev libomp-dev
# activate the virtual environment now.
# see this page on how to set up an virtual environment.
# for instance, pp
$ workon pt
(pp) $ pip3 install setuptools numpy Cython
(pp) $ pip3 install requests
# install PyTorch and Torchvision
(pp) $ pip3 install torch torchvision --index-url
# you may like to install Torchaudio also
(pp) $ pip3 install torchaudio --index-url

After a successful installation, you can check PyTorch with the following commands.


Back to content