Manually installing python 3.11 on DietPi

Originally I made this guide for internal use in a private project on github, but I thought it wouldn’t hurt to repost it here, in the off-chance someone may find it useful.

It was made using python 3.11.2 and DietPi 8.15, though it should work for other versions all the same. I do not think it to be complete nor exhaustive, so if you find any errors and have useful additions, let me know and I shall edit.

Prerequisite packages

Some of these you may or may not already have:

sudo apt install software-properties-common wget xz-utils gcc 
sudo apt install openssl libssl-dev libffi7 libffi-dev

Not certain if actually needed

sudo apt install build-essential

(Installs g++ which is not used in building python, afaik)


Always update first

sudo apt update
sudo tar -xf Python-3.11.2.tar.xz
cd Python-3.11.2

Find you openssl path with the headers

sudo find / -name "ssl.h"

:warning: In my case it was /usr/include/openssl/ssl.h and for some reason you mustn’t specify the .../include part. The call that worked for me (but not neccessarily you, if your ssl.h is somewhere else):

sudo ./configure --enable-optimizations --with-openssl=/usr

If you see the line checking for openssl/ssl.h in /<directory>... yes then you made it. If not, adjust the argument to --with-openssl (watch the output carefully or divert it into a file and search for the line¹)

Dont ignore warnings here, if it wants additional packages )like pkg-config, install them


Run all of these:

sudo make
sudo make test

The make test is the longest step and the step that will show you if packages are missing/cannot be found

sudo make altinstall



then test for ssl

import ssl

If you need to run pip use

python3 -m pip <pip syntax here>

¹ You might use tee for that, as it copies stdout to a file and stdout, like so

sudo <your command> | tee -a myfile.txt
1 Like