Update Python to the new version 3.9

This worked for me but haven’t tried running HA yet.
I just downloaded Python-3.8.6, and installed via make altinstall on Ubuntu 18.04.5 LTS full up to date.
The created a virtual enviroment for HA

steps:

python3.8 -m venv py38ha
source py38ha/bin/activate
(py38ha) pip install wheel colorlog mysqlclient
(py38ha) pip install homeassistant

and I received the same error/warning. which brought me here.

Did you update your startup script so that it uses the new venv?

I started again to see if I could reproduce, but this time after install python3.8 and activating the venv, I updated pip (py38ha) pip install pip --upgrade and I did not get the error again.

Thanks man, your steps worked perfect. Really appreciate it.

Btw, is it normal that the “sudo apt-get install” step installed almost 600 MB of new packages? That seems insane.

1 Like

If you haven’t done an update in a while, yes :wink:

The system is up to date, just tons of new stuff being installed for this upgrade. Well, as long as it’s working… :wink:

unable to get past this started with 3.9 and even went back to 3.8.6 on python same error

Error: Command ‘[’/home/pi/bin/python3.8’, ‘-Im’, ‘ensurepip’, ‘–upgrade’, ‘–default-pip’]’ returned non-zero exit status 2.

this is what I get with 3.9.0

homeassistant@raspberry:/srv/homeassistant $ python3.9 -m venv .
Error: Command ‘[’/srv/homeassistant/bin/python3.9’, ‘-Im’, ‘ensurepip’, ‘–upgrade’, ‘–default-pip’]’ returned non-zero exit status 1.

Exit status one usually means a permissions problem.

I followed these directions above and they worked well. I have HA installed manually on a RPi and the only issue I had was errors setting up Zwave, specifically

ERROR:homeassistant.util.package:Unable to install package homeassistant-pyozw==0.1.10

and

error: openzwave-embed/open-zwave-hass/libopenzwave.a: No such file or directory

The solution is in this thread: Unable to build zwave | homeassistant-pyozw · Issue #18659 · home-assistant/core · GitHub

Install these two as the pi user:

sudo apt-get install libudev-dev
sudo apt-get install libopenzwave1.5-dev

and then this one in your virtual environment as the homeassistant user.

pip3 install homeassistant-pyozw python-openzwave

Ok, so is this done in the hass.io system which is “closed” and does not allow apt-get?

No. If you’re running Home Assistant OS (the name for Hassio since January), or Supervised, or Container, you don’t need to do this.

You only need to worry about Python versions if you’re running HA Core - with pip install.

1 Like

I think it’s fair to say that most Homeassistant users are running Raspberry Pi OS on a Raspberry Pi. Has any thought been given to the wisdom of requiring a Python version ahead of what Raspberry Pi OS offers?

Yes

Three out of four methods use Docker, where it’s not a problem - most HA users don’t run RPi OS :wink:

Oh, and unless you’re trying to directly run locally installed software, switching to Docker is trivial.

3 Likes

There’s probably a fair share of people using Raspberry Pi OS, but most of them run HA supervised which doesn’t care about your python version. People using venv are the minority and most of them use it because they have enough experience with linux/python and don’t have any issue with updating a python version. The other people that use venv are in my experience using venv because they started when the docker installs didn’t exist and never bothered to switch to the docker installs or people that read a tutorial somewhere that advised them to install it in a venv or people that simply choose the wrong install method because they are afraid of docker or dimilar things.

When you live at the wrong end of a very expensive, metered satellite link, switching to docker isn’t quite so trivial.

Then I’m afraid you’re just going to have to roll with manually installing Python every 12 months :wink:

Or take this sort of dismissive attitude as a hint that maybe I should give up on Homeassistant after 4 years.

1 Like

Not at all, but it is what it is. You’re between a rock and a hard place, and the only practical solution is for you to up-skill. The developers aren’t going to change their mind because a minority of users, using a method they’ve tagged as an expert installation method, have issues.

Learning how to upgrade Python, or even just following any of the many guides (see below), is really the only option you’ve got here:

Most of these are the same basic process, and will work for version 3.8, 3.9, 3.10 and so on. Heck, I ended up writing a script I can run that does all the heavy lifting for me.

3 Likes

Another more basic question:
I have a Pi core installation i.e. a user “pi” and a user “homeassistant” with its own virtual env for a fresh python3.8.6 installation.
In my understand the venv python (under /srv/homeassistant) has still access to all modules with I install as user “pi” (under /usr/local/lib/python3.8/site-packages) ?

But if I check sys.path in the my venv Python:

>>> import sys
>>> sys.path
['', '/usr/local/lib/python38.zip', '/usr/local/lib/python3.8', '/usr/local/lib/python3.8/lib-dynload', '/srv/homeassistant/lib/python3.8/site-packages']

there is no path to …site-packages? Is this normal?
As an example I installed module lxml as user pi:

sudo pip3 install lxml

but when switch to venv “homeassistant” the module is not there…?