Home assistant not starting after upgrading to python 3.7

For a while home assistant was bugging me with messages that I should upgrade python, because python 3.5 would no longer be supported.

I have home assistant running on a nuc on Debian. I found this guide to upgrade python: https://exitcode0.net/debian-9-how-to-upgrade-python-3-5-to-python-3-7/

I executed these steps:

After those steps I restarted home assistant, but I noticed it was still telling me I was using python 3.5. I also noticed that when I executed python --version, I got version 3.7, but when I executed ython3 --version, I got version 3.5

I figured that I maybe had to point python 3 to the new version too, so I executed:
update-alternatives --install /usr/bin/python3 python3 /usr/local/bin/python3.7 10

Not sure if that was a good thing to do, because after it, home assistant wouldn’t start anymore at all. In the log I get these errors:

Dec 01 15:45:09 nuc systemd[1]: Started Home Assistant.
Dec 01 15:45:09 nuc hass[1679]: Traceback (most recent call last):
Dec 01 15:45:09 nuc hass[1679]:   File "/home/nuc/homeassistant/bin/hass", line 6, in <module>
Dec 01 15:45:09 nuc hass[1679]:     from homeassistant.__main__ import main
Dec 01 15:45:09 nuc hass[1679]: ModuleNotFoundError: No module named 'homeassistant'
Dec 01 15:45:09 nuc systemd[1]: [email protected]: Main process exited, code=exited, status=1/FAILURE
Dec 01 15:45:09 nuc systemd[1]: [email protected]: Unit entered failed state.
Dec 01 15:45:09 nuc systemd[1]: [email protected]: Failed with result 'exit-code'.

I thought that maybe I was on a too old version of home assistant, so I tried to upgrade it by executing:

cd homeassistant
source bin/activate
python3 -m pip install --upgrade homeassistant

But that gave me the error “No module named pip”
According to this page: https://www.home-assistant.io/docs/installation/troubleshooting/ it should be fixed by executing the get-pip.py script, but that just gave me the next error:

subprocess.CalledProcessError: Command '('lsb_release', '-a')' returned non-zero exit status 1.

So now I’m kind of stuck. Any idea how to get home assistant working again?

You needed to rebuild your venv - effectively a fresh install.

Hi,

as I see some similarities with my problem and this thread I’d like to dig it out and append it.

I also just upgraded python on my Raspberry with a built from scratch, in my case to v3.9, and now I’m also getting this one

subprocess.CalledProcessError: Command '('lsb_release', '-a')' returned non-zero exit status 1.

Difference here is, that I already had/have reinstalled the venv successfully and HA is running smooth.
So far. Above error appeared when I added a new device (a vacuum) so that a package-install was triggered on a HA-restart.
On further investigation I also discovered the following circumstance:

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

(Python3 is symlinked to Python3.9, not sure if relevant)

I’m not sure if these two errors belong together but something is wrong here. Is somthing like python3.9-venv needed?!
Can anybody explain that behavior and help me?

I’m going to guess that you replaced the version of Python3 that came with the OS with 3.9, and that’s broken parts of your OS.

1 Like

Well… I removed my symlink Python3>Python3.9, executed again

homeassistant@raspberrypi:/srv/homeassistant $ python3 -m venv .

and it worked?! Everything, the lsb_release-Error is also gone. So - thanks a lot for this little hint :slight_smile:

But just to bring this to an end, I want to understand the circumstances a bit better. This confuses me:

(homeassistant) homeassistant@raspberrypi:/srv/homeassistant $ python --version
Python 3.9.0

How is this possible, when I start it with Python3? Because I created the venv initially with 3.9 and that is one of the purposes of a venv? So it does only matter a bit, with which version I start the venv!? I honestly admit that I have a small knowledge gap here regarding the venv…
Another small hint or link is enough, I don’t want to waste your time with a long explanation.

Yes. When you create a venv it’s created with that version of Python, and the python3 executable in there is linked to the real one. You can follow the chain by doing the following with the venv activated:

ls -l $(which python3)

That will show something like the following (which is on mine):

lrwxrwxrwx 1 homeassistant homeassistant 9 Aug  3 06:12 /srv/ha_venv/3.8.5/bin/python3 -> python3.8

Yours will say python3.9 though :wink: Then you can do

ls -l $(which python3.9)

and you’ll get something like this (again, from mine), except yours will say python3.9:

lrwxrwxrwx 1 homeassistant homeassistant 24 Aug  3 06:12 /srv/ha_venv/3.8.5/bin/python3.8 -> /usr/local/bin/python3.8

Okay, got it. Thank you very much :slight_smile:
Probably I’ll overthink the use of the a venv and take a further look on the docker-stuff, as you recommend it in many other posts. My assumption was that the needed efford for [HA Core w/ venv]<[docker], when you don’t know both but Linux in general.