Update Python to the new version 3.9

I’ve been looking into this and the only issue I see, running a newer version of python alongside package base, is that no automatic updates will happen.

Every 2 months a point release will occur, so to stay up-to-date with bug fixes (or at least follow the Docker releases as mentioned above – follow Docker ) one will need to re-install the new python and upgrade the venv.

As to upgrading the venv I believe it may be as simple as running “python3.x -m venv --upgrade ENV_DIR” where “3.x” is replaced with whichever python to which you’re upgrading. I’m guessing you don’t want to use this for 3.7.3 -> 3.8, for example … just updating point releases.

(Looking into this has me wondering: should we have been doing the --upgrade command on the venv all along; it’s not clear to me that “apt upgrade” package updates will find their way into the venv.)

I understand the need to limit supported versions (especially if moving between releases guarantees breakage). This will be interesting to see what happens when 3.7 support is removed as every rpi user that’s not on Docker will be affected. I personally am stubbornly refusing to move to Docker – I actually went through the official install and onboarding on a spare rpi as a test and still strongly prefer my existing setup. I may need to revisit this as it seems like the maintenance burden is going up.

2 Likes

The same thing happened when Python 3.5 was deprecated, and 3.6. This isn’t a new dance :wink:

The answer will be that many people will altinstall Python 3.8 (and in the next year 3.9), and others will switch to Docker. Some will just stay on the last version of HA that supports their version of Python.

Based on h_t_t_p_s://www.home-assistant.io/docs/installation/raspberry-pi/ (my instalation) and some google search, i,ve update python 3.7.0 to 3.8.6 with no major problems, Just had to adjust some configuration in configuration.yaml, and just work like charm, and test in other instalation version 3.9.0 and run as well too, Hope this help:

#dont have to change anything in home assistant “boot”.

#With PI user

sudo apt-get update

sudo apt-get upgrade -y

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

wget -O /tmp/Python-3.8.6.tar.xz https://www.python.org/ftp/python/3.8.6/Python-3.8.6.tar.xz

cd /tmp

tar xf Python-3.8.6.tar.xz

cd Python-3.8.6

./configure

sudo make altinstall

sudo apt -y autoremove

cd

rm -r /tmp/Python-3.8.6

rm /tmp/Python-3.8.6.tar.xz

sudo mv /srv/homeassistant /srv/homeassistant_old

cd /srv

sudo mkdir homeassistant

sudo chown homeassistant:homeassistant homeassistant

sudo -u homeassistant -H -s

cd /srv/homeassistant

/usr/local/bin/python3.8 -m venv .

source bin/activate

python3 -m pip install wheel

pip3 install homeassistant

pip3 install websocket-client #sonoff if add in costum components

pip3 install mysqlclient #mysql if run HA db in mariadb/mysql

hass # here we see the error´s and adjust config

for version 3.9.0 just change “3.8.6” to 3.9.0 and

“/usr/local/bin/python3.9 -m venv .”

#Best regards Igor

20 Likes

Yeah, and don’t use 3.9.0, as mentioned back here :wink:

Thanks for your very clear and concise manual, I have a question, I don’t use sonoff at all and I don’t have the db anywhere else, I understand that the last commands are not necessary.

I mean these!

pip3 install websocket-client #sonoff if add in costum components

pip3 install mysqlclient #mysql if run HA db in mariadb/mysql

Gracias

Yes, if you dont have, dont need. (Saludos)

Just for testing :slight_smile:

I like HA in venv do things the hard way, this way I´m learnig a litle bit every day. No only home assistant “sings” but debian it self. Docker is a solution but no the same thing,

Likewise, since I installed it following an official manual, I have learned many things and I am happy about it. I would like to be able to update without problem and continue learning, without the need to change installation. I also have quite a few things configured that I will have to modify or tweak just to change the installation.

So I want to update Python and continue as before.

Thanks, I’ll give it a try these days! First I want to make a backup copy of the disk where the system is installed.

1 Like

Oh, don’t get me wrong, I run HA in a venv too - but it does require more effort, skill, and the ability to Google, than if you’re on Docker.

1 Like

Unless you run local software, moving to Docker requires no changes to your config.

In did, but that´s the point, more efford = more skill´s.

Hi guys!

Thanks a lot for the procedure igorlemos…
I have the same configuration (without the extra) and that worked smoothly …

But I got the following message while installing Home Assistant:

pip3 install homeassistant

ERROR: After October 2020 you may experience errors when installing or updating packages. This is because pip will change the way that it resolves dependency conflicts.

We recommend you use --use-feature=2020-resolver to test your packages with the new resolver before it becomes the default.

aiohttp 3.6.2 requires multidict<5.0,>=4.5, but you’ll have multidict 5.0.0 which is incompatible.

Up to now, everything is working fine… I am just wondering if that could be a problem?
Later on…

Thanks,

Hello, me again…
I just found out this within the log, related to Insteon:
Logger: homeassistant.config_entries
Source: components/insteon/init.py:162
First occurred: October 12, 2020, 9:21:28 PM (1 occurrences)
Last logged: October 12, 2020, 9:21:28 PM

Error setting up entry for insteon
Traceback (most recent call last):
File “/srv/homeassistant/lib/python3.8/site-packages/homeassistant/config_entries.py”, line 231, in async_setup
result = await component.async_setup_entry(hass, self) # type: ignore
File “/srv/homeassistant/lib/python3.8/site-packages/homeassistant/components/insteon/init.py”, line 162, in async_setup_entry
model=f"{devices.modem.model} (0x{devices.modem.cat:02x}, 0x{devices.modem.subcat:02x})",
File “/usr/local/lib/python3.8/enum.py”, line 669, in format
return cls.format(val, format_spec)
ValueError: Unknown format code ‘x’ for object of type ‘str’

Any idea?

Thanks,

@paul5 based on the error message it appears you are using python 3.8. The error message does not appear to be related to any python version but rather to something in your environment with the startup of Insteon. I am going to send you a direct message to help debug your issue.

aiohttp 3.6.2 requires multidict<5.0,>=4.5, but you’ll have multidict 5.0.0 which is incompatible.

pip3 install --upgrade --force-reinstall multidict==4.7.6

This will work unless something else (other than HA) needs multidict 5.0.0. The alternative is to install a later version of aiohttp that’s compatible with both HA and multidict 5.0 (if it exists).

That installed without any error message…
There is nothing else then HA and Mosquitto on this…

pi@hassio:~ $ pip3 install --upgrade --force-reinstall multidict==4.7.6
Defaulting to user installation because normal site-packages is not writeable
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Collecting multidict==4.7.6
Downloading multidict-4.7.6.tar.gz (50 kB)
|████████████████████████████████| 50 kB 794 kB/s
Installing build dependencies … done
Getting requirements to build wheel … done
Preparing wheel metadata … done
Building wheels for collected packages: multidict
Building wheel for multidict (PEP 517) … done
Created wheel for multidict: filename=multidict-4.7.6-cp38-cp38-linux_armv7l.whl size=180741 sha256=ee5614a9eb8b15067bb7689837fb934f5cad0c14cd281aa34d215baff0cfe4d5
Stored in directory: /home/pi/.cache/pip/wheels/78/82/3a/e149e5c0e123a9094d46ec7249c95ceff6d63c90dcdd2c295d
Successfully built multidict
Installing collected packages: multidict
Successfully installed multidict-4.7.6

Thanks!

Don’t mean to deviate from the thread, but as an FYI to anyone looking through it…
If anyone is using Ubuntu bionic 18.04.x, you may be able to update Python to 3.8.0 from the Ubuntu distribution (at least for amd64).

$ sudo apt install python3.8
$ sudo apt install python3.8-venv 
$ sudo apt install python3.8-dev
2 Likes

yes I did and nothing seems to work.

Exactly what doesn’t work?