Skip to content

Instantly share code, notes, and snippets.

@facundobianco
Last active February 11, 2021 15:29
Show Gist options
  • Save facundobianco/3e2833b93420893faf7dcf0c8aa8a785 to your computer and use it in GitHub Desktop.
Save facundobianco/3e2833b93420893faf7dcf0c8aa8a785 to your computer and use it in GitHub Desktop.
Upgrade HA to latest stable version in a virtualenv

Home Assistant in virtualenv: Install Python 3.9.1 on Raspberry OS

This short guide explains how to upgrade Home Assistant to latest stable version inside a Python virtual environment.

Home Assistant latest release v2021.2 requires Python >= 3.8 to run. The good news is that fully supports Python v3.9. In this guide will install Home Assistant v2021.2.3 (released on Feb 11).

First of all, you should install Python v3.9.1. There ain't a binary package so you will need to compile. Run as root

apt install --no-install-recommends -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
cd /usr/local/src
wget -qO - https://www.python.org/ftp/python/3.9.1/Python-3.9.1.tar.xz | tar xf
cd Python-3.9.1
./configure --prefix=/usr/local/opt/python-3.9.1 --enable-optimizations
make
make altinstall
for FILE in easy_install-3.9 pip3.9 python3.9 python3.9-config
  do ln -s /usr/local/opt/python-3.9.1/bin/${FILE} /usr/bin/
  done

Second, connect to your actual virtual environment and run

pip freeze > requirements.txt
deactivate

Then, fix dependencies for new virtual environment

apt install -y libjpeg-dev zlib1g-dev
sed -e 's/=.*//' -e 's/^homeassistant/&==2021.2.3/' -i requirements.txt

And create a virtual environment with Python3.9 and install Home Assistant

python3.9 -m venv virtualenv-3.9
source virtualenv-3.9/bin/activate
pip install -r requirements.txt --use-feature=2020-resolver

Finally, run Home Assistant service

/home/homeassistant/virtualenv-3.9/bin/python3.9 /home/homeassistant/virtualenv-3.9/bin/hass \
  -c /home/homeassistant/.homeassistant
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment