Python upgrade

I’ve figured out how to update python without affecting the OS python installation, using pyenv.

Note: this will take a few hours of your time, between installing and building python and home-assistant.

I’m using a virtualenv install of HA, running on a Pi 2. Building python took almost 30 minutes, + you will have to reinstall homeassistant (another 30 minutes). Don’t worry about your configuration files (backup just in case), this will install a new virtualenv, so after you test to make sure everything works, you can delete the /srv/homeassistant.

Second note: I’m running Raspbian Stretch, and I understand Raspbian Buster is coming out in a few days, but I feel this will be a more maintainable installation of Hass. If this has happened once, it will happen again. Else, you don’t have to upgrade to Buster if you don’t want to. :man_shrugging:

Run 1-6 as your homeassistant user
sudo -u homeassistant -H -s

  1. Install pyenv, I did the Github version, so follow 1-5. (You can replace .bash_profile with .bashrc or .bash_aliases)
  2. (Step 6 from above^) Choose your python version and start installing. I used 3.7.3 and it took ~30minutes.
    pyenv install 3.7.3
  3. Install pyenv virtualenv
  4. Create a new virtualenv with your new python
    pyenv virtualenv 3.7.3 home-assistant
  5. Jump into this virtualenv
    pyenv activate home-assistant
  6. And install home-assistant again (~30 minutes)
    python3 -m pip install wheel homeassistant
  7. While that is installing, you can update your systemd, or other, config for Hass with a user with sudo powers. You can backup this file, to be safe.
    sudo nano /etc/systemd/system/[email protected]
    Change the ExecStart= line to ExecStart=/home/homeassistant/.pyenv/versions/home-assistant/bin/hass -c "/home/homeassistant/.homeassistant"
    Run sudo systemctl daemon-reload to make sure this change is registered with systemd.
  8. I had Hass stopped while I was doing this, but this should work once Hass is re-installed
    sudo systemctl restart [email protected]
1 Like