Upgrading HomeAssistant Core in a Python VE

Great post ! Thank you !
No chance with “sudo python3.10 -m venv .” at step E
because I don’t know the homeassisant password but “python3.10 -m venv .” did the job. Then same thing with “sudo -u homeassistant -H -s” just after. I omit it.

Now my HASS is running with Pyhton 3.10.9 and next HA upgrade won’t be an issue.

cheers

1 Like

It’s a pleasure!

1 Like

follow your instructions for updating Python

Thanks for the instruction. Manage to upgrage Python but get an error at the following instruction in section E

Error log

  Preparing metadata (setup.py) ... error
  error: subprocess-exited-with-error

  × python setup.py egg_info did not run successfully.
  │ exit code: 1
  ╰─> [55 lines of output]
      /srv/homeassistant/lib/python3.10/site-packages/setuptools/config/setupcfg.py:508: SetuptoolsDeprecationWarning: The license_file parameter is deprecated, use license_files instead.
        warnings.warn(msg, warning_class)
      /srv/homeassistant/lib/python3.10/site-packages/setuptools/installer.py:27: SetuptoolsDeprecationWarning: setuptools.installer is deprecated. Requirements should be satisfied by a PEP 517 installer.
        warnings.warn(
      WARNING: The wheel package is not available.
      WARNING: The wheel package is not available.
        error: subprocess-exited-with-error

        × python setup.py bdist_wheel did not run successfully.
        │ exit code: 1
        ╰─> [8 lines of output]
            /srv/homeassistant/lib/python3.10/site-packages/setuptools/config/setupcfg.py:508: SetuptoolsDeprecationWarning: The license_file parameter is deprecated, use license_files instead.
              warnings.warn(msg, warning_class)
            usage: setup.py [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
               or: setup.py --help [cmd1 cmd2 ...]
               or: setup.py --help-commands
               or: setup.py cmd --help

            error: invalid command 'bdist_wheel'
            [end of output]

        note: This error originates from a subprocess, and is likely not a problem with pip.
        ERROR: Failed building wheel for cffi
      ERROR: Failed to build one or more wheels
 

Any suggestions? Thanks

Solved the issue, problem was related to wheel
following action resolved the issue

python3 -m pip install wheel

Android 13, chrooted in ubuntu jammy

I just deleted folder and install HA core normally, took couple of minutes.

sudo -u homeassistant -H -s
cd /srv/homeassistant

rm -r *

python3 -m venv .
source bin/activate

python3 -m pip install wheel
pip3 install homeassistant

Great was about to respond with that :slight_smile:

If anyone has problems with Bluetooth after upgrading to Python 3.10 try this solution here. Short version

sudo setcap 'cap_net_raw,cap_net_admin+eip' /usr/local/bin/python3.10
sudo systemctl restart home-assistant@homeassistant

Sorry I might sound stupid but how do I update Python if I am using the HAOS running on a VM on Proxmox?

image

Am I missing something ? The base OS I guess is Debian/Ubuntu but how can I run other commands rather than the ones the CLI offers ?

thanks

This guide is not for HAOS but for HA Core.
In your case Python is updated by the OS.

I would like to suggest to stop EVERY possible service (HA, as well) before running “make”, if you are an old Rpi (like mine 3B+) or it will take a very looooooong time!

Thanks for trying to shed some light on the worst mess I’ve seen in 43 years since I started with an Apple ][!

  1. Is home-assistant (with -) above a typo?
  2. Edit: You use sudo with python3 -m venv . The docs don’t.
  3. Thanks for the suffice-with-3.10 tip. Was about to use 3.11. Edit: Will simply KILL it. How about trying with pyenv?

Later
G.

Hi Maarten,

This unfortunately is the most complex part of the upgrade. Each persons HomeAssistant Integrations are different, so the requirements are different.

What is happening here is the PIP installer is trying to install all the requirements / prerequisites which are unique to your environment & dependant on integrations / components you have configured in HASS.

You might need to try and resolve those individually, or worst case, you might need to edit your requirements.txt file, and remove the items which PIP has a problem with installing.

One item that might be easily resolvable for instance is the “license_file parameter is deprecated, use license_files instead” where you might just need to update the requirements.txt file to use “license_files” instead of “license_file”.

Hi, I’m running HA with a Python VEnv too and have done multiple Python-Updates ( 3.9, 3.10, 3.11) since I started with HA.
My recommendation is NOT to use the “requirements.txt”-approach.
After downloading and installing Python, creating a new VEnv for the new version like you do describe in the guide I always handled it like a new install of HA and installed HA with pip as described in documentation, then changed the service to point to the new folder and started HA. On startup ( which takes quite a while in this case) it pulls all missing requirements, including those for custom components.
Advantage is that you don’t carry over any dependencies from the old VEnv and the old Python-version

Of course this approach also might produce problems
For cryptography a manual install of rustc was required ( believe this was with Python 3.9), otherwise Python was unable to compile the package
Manually installed python libraries have to be installed again. For example I’m using a Infrared Receiver and the “lirc”-package requires manual installation from source into each new environment

my 2 cents
Armin

Thanks for a great guide @Pieter_Rossouw ! Below is a quick guide that describe what I did to go from Python 3.11 to 3.12.

Assumptions

  • HA is run as root. I personally run it in a LXC container (Proxmox). See additional steps provided in the first post in this thread for steps required to use a different user.
  • The Python runtime previously installed using the deadsnakes PPA.
  • Packages already installed: apt install wget build-essential libncursesw5-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev libffi-dev zlib1g-dev python3-pip

Install new python version

apt install python3.12 python3.12-dev python3.12-venv

Stop HA

systemctl stop home-assistant@root

Write package requirements to requirements.txt

cd /root/.homeassistant
source /srv/homeassistant/bin/activate
pip3 freeze –local > requirements.txt
exit

Backup existing HA runtime

cd /srv
mv homeassistant homeassistantold

Set up new runtime

cd /srv
mkdir homeassistant
cd /srv/homeassistant
python3.12 -m venv .

Activate python env

source /srv/homeassistant/bin/activate

Install dependencies

cd /root/.homeassistant
pip3 install --upgrade pip
pip install --upgrade pip
pip3 install -r requirements.txt

Install HA

pip3 install homeassistant

Start it again

systemctl start home-assistant@root

1 Like

I just upgraded this and did the same … no requirements.txt. Just backup the old install and reinstall from scratch. Assuming you have the home-assistant service (for stop and start) …

sudo apt update
sudo apt install python3.12
sudo apt install python3.12-venv
sudo apt install python3.12-dev
sudo systemctl stop home-assistant@homeassistant
cd /srv
sudo mv homeassistant homeassistant-3.11
sudo python3.12 -m venv homeassistant
sudo chown -R homeassistant:homeassistant homeassistant/
pip3 install wheel
cd homeassistant
sudo -u homeassistant -H -s
source bin/activate
pip3 install --upgrade homeassistant
pip3 install --upgrade home-assistant-frontend
exit
sudo systemctl start home-assistant@homeassistant

Worked a charm. Yes you patiently wait for all the python to compile and such (5 minutes or so) but up and running and faster than before

Hello, I’m having this problem… how to solve it?
thanks

root@raspberrypi:/home/lucavasini# sudo apt update
Hit:1 http://deb.debian.org/debian bookworm InRelease
Hit:2 http://deb.debian.org/debian-security bookworm-security InRelease
Hit:3 http://deb.debian.org/debian bookworm-updates InRelease
Hit:4 http://archive.raspberrypi.com/debian bookworm InRelease
Hit:5 https://download.docker.com/linux/debian bookworm InRelease
Ign:6 https://ppa.launchpadcontent.net/deadsnakes/ppa/ubuntu bookworm InRelease
Err:7 https://ppa.launchpadcontent.net/deadsnakes/ppa/ubuntu bookworm Release
  404  Not Found [IP: 185.125.190.80 443]

I’ve been able to upgrade from 3.9 to 3.11 with freebsd successfully. I did the requirements things, then I did it again without the requirements steps. The later is indeed superior. Much faster, not installing uneeded deps.

Here’s some fix I needed for FreeBSD:

After installing homeassistant:

pip3 install numpy
pip3 install git+https://github.com/rhasspy/webrtc-noise-gain.git|

I also have a problem with pyturbojpeg==1.7.1. I can install the updated version, but something requires this version that won’t install. That being said, it works so far. Note that my upgrade is small. I’ve started using ha like 3 days ago.

# update Home Assistant Core (HAC) venv on an Ubuntu 22.04 (jammy) system to use python3.12 in order to support "Home Assistant 2024.4" and newer HAC versions

# scenario:
# * Raspberry Pi 4B with Ubuntu 22.04 (jammy)
# * currently the HAC installation uses python3.11.9
# * HAC installation was previously (e.g. in 2022) set up as per
#   * https://www.home-assistant.io/installation/linux#install-home-assistant-core
#   * https://www.home-assistant.io/installation/raspberrypi#install-home-assistant-core
#   * notably, HAC venv is located at "/srv/homeassistant"
# * usual HAC update steps as per https://www.home-assistant.io/common-tasks/core/#update 
#   don't update beyond 2024.3.3 because HAC 2024.4+ requires python3.12 .

# if not already set up, add the deadsnakes PPA so that python3.12 is available for installation via apt
# see https://launchpad.net/~deadsnakes/+archive/ubuntu/ppa
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt update

# install all python3.12-relevant packages:
sudo apt install python3.12 python3.12-dev python3.12-venv

# sanity-check *system-wide* python3.12 installation:
which python3.12
# shall output "/usr/bin/python3.12"

python3.12 --version
# shall output "Python 3.12.x", e.g. "Python 3.12.4"

# stop homeassistant service
sudo systemctl stop homeassistant.service

# switch to Unix user "homeassistant"
sudo -u homeassistant -H -s

# now in the role of Unix user "homeassistant" 
# backup HAC venv directory
mkdir -p "${HOME}/backups/homeassistant/2024-07-01"
rsync -a /srv/homeassistant/ "${HOME}/backups/homeassistant/2024-07-01/homeassistant"

# see https://docs.python.org/3/library/venv.html
# while OUTSIDE of any venv, upgrade the HAC venv by executing
# "... -m venv --upgrade ..." with the desired python version,
# i.e. by explicitly using the "python3.12" executable:
python3.12 -m venv --upgrade /srv/homeassistant

# if this results in an error with message:
#   "Error: Unable to create directory '/srv/homeassistant'",
# then maybe the path "/srv/homeassistant" has a symlink along its path components?
# if so, then try the following command instead:
# python3.12 -m venv --upgrade "$(realpath /srv/homeassistant)"
#
# command shall exit without any output and with exit status 0.

# activate the upgraded venv
source /srv/homeassistant/bin/activate

# you are now as user "homeassistant" in an homeassistent (the application) venv.
# prompt should look similar to the following:
# (homeassistant) homeassistant@mymachine:/srv/homeassistant$

# ... ignore for a moment that the command "python --version" may still output e.g. "Python 3.11.9", not "Python 3.12.x"

pip3 install --upgrade homeassistant
# olala! something works:
# output:
#   Collecting homeassistant
#     Downloading homeassistant-2024.6.4-py3-none-any.whl.metadata (4.3 kB)
# ...
#
# collects packages, builds wheels, and installs collected packages.
# this can easily take over ten minutes on a Raspberry Pi 4B 
#
# in my case I got the following notice:
#   [notice] A new release of pip is available: 24.0 -> 24.1.1
#   [notice] To update, run: pip install --upgrade pip
# following suit:
pip install --upgrade pip

# continuing with https://www.home-assistant.io/common-tasks/core/#configuration-check :
hass --script check_config

# easily takes 30 minutes and more, as several packages may need to be compiled to the target architecture.
# outputs e.g.:
#   INFO:homeassistant.util.package:Attempting install of colorlog==6.8.2
#   Testing configuration at /home/homeassistant/.homeassistant
#   INFO:homeassistant.helpers.storage:Migrating core.entity_registry storage from 1.13 to 1.14
#   INFO:homeassistant.util.package:Attempting install of home-assistant-frontend==20240610.1
#   ...

# sanity check if the following command gives sensible output on your configuration:
hass --script check_config --info all

# we're done with the Home Assistant update/upgrade.

# time to start up Home Assistant as you usually do
# in my case the following steps were:
# leaving the venv:
deactivate

# leaving the shell as user "homassistant" to get back to my default user
exit

# now back in the role of my default user
# prepare to monitor the usual logs to see if everything starts up nicely, e.g. with
# journalctl -x -f
# Let's start Home Assistant now; in my case it goes like so:
sudo systemctl start homeassistant.service

# took 30 seconds or so until the first Home Assistant log entries appeared
# then the journalctl log shows that even more things get installed/updated, such as:
#   INFO (MainThread) [homeassistant.setup] Setup of domain logger took 0.23 seconds
#   ...
#   INFO (SyncWorker_1) [homeassistant.util.package] Attempting install of bar==4.5.6
# ... but the web interface is already reachable

This post is not for HAOS, but rather running HomeAssistant on a Ubuntu OS in a Pythone Virtual Environment.