PyTorch - Q-engineering
Q-engineering
Q-engineering
Go to content
images/empty-GT_imagea-1-.png
PyTorch on Raspberry Pi 5

Install PyTorch on a Raspberry Pi 5.

Last updated: May 19, 2024

Introduction.

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, pyt
$ mkvirtualenv pyt
# or if you have already a pyt environment
$ workon pyt
(pyt) $ pip3 install setuptools numpy Cython
(pyt) $ pip3 install requests
# install PyTorch and Torchvision
(pyt) $ pip3 install torch torchvision --index-url https://download.pytorch.org/whl/cpu
# you may like to install Torchaudio also
(pyt) $ pip3 install torchaudio --index-url https://download.pytorch.org/whl/cpu

PyTorchRdy

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

PyTorch_2_2_RPi5

TorchVision_0_17_RPi5
images/GithubSmall.png
images/YouTubeSmall.png
images/SDcardSmall.png
Back to content