Python 3.9 install on Raspberry PI OS

This Tutorial is to Be used at your Own Risk make sure you Back up your Home Assistant Files and any other files you don’t want to lose Before Starting. it is easy to break it takes time Rebuilding your Home assistant from Scratch

This instruction will install Python 3.9 onto your System and allow you to us it as default.

This instruction is intended for a clean install of Home assistant best used with this instruction Installing Home Assistant

"DO NOT COPY AND PASTE STUFF IN QUOTES"

“LOG INTO THE TERMINAL.”

“GET LATEST UPDATES”

sudo apt update

sudo apt upgrade -y

“INSTALL THE DEPENDENCIES NEEDED TO BUILD”

sudo apt-get install build-essential tk-dev libncurses5-dev libncursesw5-dev libreadline6-dev libdb5.3-dev libgdbm-dev libsqlite3-dev libssl-dev libbz2-dev libexpat1-dev liblzma-dev zlib1g-dev python3 python3-dev python3-venv python3-pip libffi-dev libtiff-dev autoconf libopenjp2-7 -y

“COMPILE (Takes Awhile) INSTALLS PYTHON INTO /usr/local/bin ”

version=3.9.6
wget -O /tmp/Python-$version.tar.xz https://www.python.org/ftp/python/$version/Python-$version.tar.xz

cd /tmp

tar xf Python-$version.tar.xz

cd Python-$version

./configure --enable-optimizations

sudo make altinstall

sudo apt -y autoremove

“CLEAN UP”

cd

sudo rm -rf /tmp/Python-$version

rm /tmp/Python-$version.tar.xz

“MAKE THIS VERSION DEFUALT, DO NOT DO THIS STEP AS IT BREAKS HOME ASSISTANT INSTALL




sudo ln -s /usr/local/bin/python3.9 /usr/bin/python3.9

echo "alias python=/usr/local/bin/python3.9" >> ~/.bashrc

echo "alias python3=/usr/local/bin/python3.9" >> ~/.bashrc

source ~/.bashrc

cd ..

. ~/.bashrc

“AND VERIFY: IF SHOWING 3.7 AND 2.7 HOME ASSISTANT SHOULD INSTALL

python3 -V

python2 -V

python -V

2 Likes

Thanks, but how do you run HASS ?

$ python3 --version
Python 3.9.6

$ python3 -m pip install homeassistant
[...]Successfully installed [...] homeassistant-2021.8.0 [...]
$ hass
bash: hass: command not found

OK, I have to add in bashrc :

export PATH=$PATH:/home/homeassistant/.local/bin

Now I can launch hass but with error:

2021-08-04 17:52:46 ERROR (MainThread) [homeassistant.auth.providers] Unable to load auth provider homeassistant: libffi.so.7: cannot open shared object file: No such file or directory

Okay if install installing home assistant then do not do the step that makes it default as the instructions states this it breaks home assistant install and there is a link to the instructions on installing home assistant at the top it is for home assistant core not sure about Hass method for installing

1 Like

On Python 3.9 I’m getting the following error (formatted for readability):

$ hass
2021-08-06 22:14:02 ERROR (MainThread) [homeassistant.auth.providers]
  Unable to load auth provider homeassistant:
    libffi.so.7:
      cannot open shared object file:
        No such file or directory

Raspbian Buster provides libffi6, not 7:

$ find /usr/lib -name libffi.*
/usr/lib/arm-linux-gnueabihf/libffi.so.6
/usr/lib/arm-linux-gnueabihf/pkgconfig/libffi.pc
/usr/lib/arm-linux-gnueabihf/libffi.so.6.0.4
/usr/lib/arm-linux-gnueabihf/libffi.a
/usr/lib/arm-linux-gnueabihf/libffi.so

As building takes quite some time, trying different build options consumes the whole evening. I’m now trying out 3.8.11. :crossed_fingers:

If you’re making 3.9 the default python ihome assistant will not work as stated in the step by step instructions the link to install home assistant after installing 3.9 is at the beginning of the page

Did you resolve the libffi.so.7 issue?

1 Like

I’ve build and installed Python 3.8 instead. Running successfully for a few days now.

1 Like

I had the same problem with missing libffi.so.7 after upgrading to Python 3.9.6 on raspbian buster which doesn’t provide libffi.so.7, only libffi.so.6.

I tried reinstalling Python 3.9.6 with “./configure --enable-optimizations –with-system-ffi” , but that did not fix the problem either. HA startup still needed the libffi.so.7 and libffi.so.7.0.4 modules.
In the end i created symbolic links for the missing two libffi7 modules, linked to the existing ffi.6 modules. Not the cleanest solution, but it worked immediaately and Raspbian Bullseye contains libffi7, so the circumvention will only be needed for a few weeks.

2 Likes

okay I found this prerelease of bullseyes

Python 3.9.7 does the same thing, I ended up going back to Python 3.8.*

1 Like

Thanks, it was exactly my problem, python 3.9 didn’t work and threw initialization errors.
My setup:
Raspberry Pi Zero W.
I installed Python 3.8 according to this instruction (slightly modified):

sudo apt-get update
sudo apt-get install -y build-essential tk-dev libncurses5-dev libncursesw5-dev libreadline6-dev libdb5.3-dev libgdbm-dev libsqlite3-dev libssl-dev libbz2-dev libexpat1-dev liblzma-dev zlib1g-dev libffi-dev
wget https://www.python.org/ftp/python/3.8.0/Python-3.8.0.tar.xz
tar xf Python-3.8.0.tar.xz
cd Python-3.8.0

(my change starts from here):

./configure --enable-optimizations
make
sudo make install

after that I had a propper version of python and managed to install Home Assistant core:

sudo apt-get update
sudo apt-get upgrade -y
sudo apt-get install -y python3 python3-dev python3-venv python3-pip libffi-dev libssl-dev libjpeg-dev zlib1g-dev autoconf build-essential libopenjp2-7 libtiff5 tzdata
sudo useradd -rm homeassistant
sudo mkdir /srv/homeassistant
sudo chown homeassistant:homeassistant /srv/homeassistant
sudo -u homeassistant -H -s
cd /srv/homeassistant
python3.8 -m venv .
source bin/activate
python3 -m pip install wheel
pip3 install homeassistant
hass

Once again thanks for the tips @Codec303 @botje !