Python upgrade

Yes docker. Debian+docker+hass.io

@anon34565116 I have to admit I’m a little lost on upgrading my Python version too. Just read the release on 0.94 and noticed the remarks on Python version deprecation.

I too am running in the venv on Python 3.5.3 so to move on to Hass 0.94 I’m going to have to bite the bullet.

I did a quick search and this post didn’t fill me with too much promise either How do I upgrade python3 version in venv

I do understand this community is NOT a help desk but I’m wondering has anyone successfully upgraded a version of Python while using Hass in a venv. If so could they give me some pointers on how they achieved this.

My install is currently on a Raspberry Pi3 running Raspbian Stretch Lite.

Silly question but would it be easier to reinstall Hass from scratch and copy over the config files. Of course it would depend on what version of Python is currently in the Raspbian Stretch repos.

3 Likes

Yeah that won’t help… I made a new raspbian lite install this week (d/l latest image and upgraded fully) for another purpose and it’s python 3.5.3…

1 Like

As I thought. Now that would have been too easy :sob:

I followed this guide, but substituted 3.7.3 instead of 3.6.x

I saw that but surely that would universally install Python across the whole distribution.

Just found this snippet from another post

sudo systemctl stop [email protected]
cd /tmp
wget https://www.python.org/ftp/python/3.7.3/Python-3.7.3.tgz
tar xzvf Python-3.7.3.tgz
cd Python-3.7.3/
./configure
make -j 4
sudo make install
python3 -V
python3 -m pip install --upgrade pip
sudo systemctl start [email protected]

Does this method sound familiar to anyone.

2 Likes

I did a quick look at the Hassbian script. It grabs Python directly instead of using the version installed in its Raspian OS.
It appears the devs have decided to make everyone slaves to their custom environments in Docker and Hassio. That is really a shame.
The devs use the excuse that the next stable Debian will have 3.7 but there is currently no release date for that.

1 Like

Not really. If you use Hassbian then you need the skills to update python there… most people insist on using hassbian because they like the control they feel they have so with great power comes great responsibility.

Docker is incredibly easier to manage anyway even for the control freaks and you don’t need to worry about any dependencies.

1 Like

Are we down to a Docker/Hassio only choice now.

I’m on Hass venv 0.93.2 so unless I get the Python situation sorted I’m frozen in time.

I looked at a Hassbian image earlier but it states that it’s Debian Buster version and comes with a health warning :warning:

Because it’s a pre-release no doubt.

I upgraded 2 Pi’s yesterday to Python 3.7.3 - I did get a few dependency issues but fairly simple fixes when you Google the error.

According to your first post, you already have Python 3.7.3 now so why not just follow the instructions for installation from the point where you create a new virtual environment… I don’t think you need to upgrade the existing one -just make a new one? Although as I say, I don’t use venv.

If there is a hassbian image with 3.7.3, maybe backup your config yaml files and use a new card, see how that goes. I remember the last time they depreciated a python version the advice was to start again! Made me glad I was using docker TBH.

No I mentioned my install contains Python 3.5.3. That’s the reason why I need to upgrade it as per advice in the HA 0.94 release notes.

Looks like I’ll need to keep digging but maybe in the meantime someone who has Hass venv installed and has upgraded their Python version will pitch in with their experiences.

Oh sorry - I confused you with the OP

No problem. I was going to make a separate post but this is something that will run as soon as venv users start upgrading to 0.94.

I would strongly recommend leaving the distribution’s Python alone and installing 3.7.3 with pyenv (pyenv-install). That way you don’t mess up anything that depends on the system Python.

https://github.com/pyenv/pyenv-installer

You probably need some prerequisites to build Python:

sudo apt libbz2-dev install libbz2-dev libncursesw5-dev libsqlite3-dev uuid-dev libreadline-dev libssl-dev

Follow the instructions on the pyenv installer page to configure your shell, then build 3.7.3:

pyenv install 3.7.3
pyenv shell 3.7.3
python -m venv [name of venv (such as homeassistant)]
[name of venv]/bin/activate
pip install homeasssitant, etc (follow HA instructions)

5 Likes

I compiled and installed python 3.7.3 on my raspberry.

I also run home assistant in a venv like you. What you can do is[1]:
python3 -m venv --upgrade /srv/homeassistant/(or whereever your homeassistant directory is).

A short ls will show:

$ ls /srv/homeassistant/lib/
python3.5  python3.7

I still don’t know how to go from here because home assistant still launches from 3.5. But we will figure it out :wink:

[1] https://docs.python.org/3/library/venv.html

I have 2.7 running along side 3.5 and 3.7, as long as you don’t adjust the symlink to /usr/bin/python3 you don’t cause problems.

Or as froz suggested give pyenv a shot.

Thanks for that.

As Python 3.6 or greater is not currently in the Raspbian Stretch repos and we don’t have a version of Raspbian Buster it means that Python needs to manually downloaded and built.

What I’m trying to put together here is a procedure to manually download and build a version of Python outside of the current repo and then replace my current Python Hass venv with this newly built version.

Why do you say that? I update python, and then replace the link so that it does use the newly installed version. This then means no upgrade of venv is required, it just uses it from there out. No issues through the last 12 months that I know of.

When I symlinked python3 to 3.7 i was getting some errors, could have just been a missing dep, but I reverted the link anyways.

I have a venv setup with HASS in it and it’s working fine, also wanted a new venv as the old one had some very very old pyozw hacks still lurking about in it that I didn’t want/need anymore :wink: