New version 0.94.0 - How update Python in a Pi3 from 3.5.3 to 3.7.3?

Version 0.94.0 has just been released, and python 3.5 version is going to be deprecated.
I have a Pi3 running Raspbian Strech Lite:
Python versions: 2.7.13 and 3.5.3

I searched about how to do it (here in the forum and in the internet, finding different results). Since I am afraid the break things, I want to be sure how to do it and I it certainly will help others in the same need, since who is running Raspbian must update for the following versions of HA.

The procedure that I found to be more reliable is this, knowing that files and syntax will have to be changed to meet the 3.7.3 version (it is 3.6.3 in the example).
I would be very grateful if someone with more knowledge than me could point us to the right direction.
Below is the procedure. Thanks!

#Upgrade to Debian Stretch (9) if you haven't already (Optional)
sudo apt-get update
sudo apt-get upgrade
sudo apt-get dist-upgrade
sudo sed -i 's/jessie/stretch/g' /etc/apt/sources.list
sudo apt-get update
sudo apt-get upgrade
sudo apt-get dist-upgrade
sudo reboot

Note:  You may need to set your static IP if you had one.  WiFi settings carry over.  You do get prompts throughout the install, I accepted all new settings.

#Update Python dependencies
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

#Download and install latest python
cd /home/pi
wget https://www.python.org/ftp/python/3.6.3/Python-3.6.3.tgz
tar xzvf Python-3.6.3.tgz
cd Python-3.6.3/
./configure
make
sudo make install

Note: Last step takes a while.

#Delete old virtual environment
cd /srv/
sudo rm -r *

Warning:  If you have any configuration files here, this is a good time to move them or back them up.

#Create new virtual environment with latest python
cd /srv/
sudo mkdir homeassistant
sudo chown homeassistant:homeassistant homeassistant
sudo su -s /bin/bash homeassistant
cd /srv/homeassistant
python3.6 -m venv .
source bin/activate

#Install latest Hass
pip3 install homeassistant
hass

Note:  First start takes a while
3 Likes

I would recommend using pyenv with the pyenv installer.

1 Like

I will take a look in your approach. Thanks.

1 Like

Dockerize it and get rid of this multi-package-manager-different-versions-hell.

3 Likes

This is what I get when I try to do the update.
pi@raspberrypi:~ $ pyenv update
-bash: pyenv: command not found

For those wanting to know the same, I point you to another answer for that question.Here.

Okay I finally got it working with the following script. Only problem I am having is HA doesn’t start automatically on reboot I have to restart HA manually.

1 Like

I believe this is for hassbian users, which is not my case.

Oh well. I just made attempt four at getting an upgrade together but it dies with compile errors
“generate-posix-vars fails” and google searching doesn’t give me a clue what that is talking about.
I confess I usually think that anything that comes in a tarball that you have to compile is too unfinished for me but I tried.

As people far smarter than I am can’t make it work I assume I’m stuck at 0.94.0 until the Raspberry people do an official python upgrade.

Check out berryconda:

It allows you to run python 3.6 on Raspbian :slight_smile:

If you’re not confident/comfortable compiling your own Python from the tarball, then that sort of upgrade is probably best avoided until the Raspbian folks update Python in the distro.

But, FWIW, I found a simple sequence of steps that worked once you have later Python compiled and installed:
I created a new venv using the newer Python, copied HomeAssistant config over to it (I chose to keep my config inside the /srv/homeassistant folder, not in ~root/ or elsewhere), and everything is happy. I had feared the worst since not many people mentioned trying HAss under anything later than 3.6.x, but this instance of 94.x seems quite happy there.

Look at my link (6 posts above). I could get it updated in kind of 20 steps that are listed there. Take a look. I could not have done it by myself alone.

Yes I’ve been trying all the things posted here but I’m a Windows/C++/Assembler bod and I don’t speak python or Unix very well. I’ll have another try.

Getting a specific Python version in Linux is often doc’d well in myriad posts. The steps are pretty simple (as long as everything goes as intended). You’ll know if the compile fails - just stop there if not comfortable figuring out what’s missing.
But if you get the newer Py installed, then just follow the HA instructions for a new setup (I use Virtualenv) and your existing config will rule it.

I don’t know python either. The steps are pretty polished right now. Sure, a very basic knowledge of what you are doing is recommended. I advice you to do a backup first.

These instructions as provided by @anon34565116 have been confirmed to work by myself and others. They are specific to a Hass installation in a venv and were carried out on a Raspbian Stretch Lite OS on a Raspberry Pi 3.

They will download Python 3.7.3 source, build, compile install and replace your current venv w

  1. 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

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

  3. cd /tmp

  4. tar xf Python-3.7.3.tar.xz

  5. cd Python-3.7.3

  6. ./configure

  7. sudo make altinstall

  8. sudo apt -y autoremove

  9. cd

  10. rm -r /tmp/Python-3.7.3

  11. rm /tmp/Python-3.7.3.tar.xz

  12. sudo systemctl stop [email protected]

  13. sudo mv /srv/homeassistant /srv/homeassistant_old

  14. sudo mkdir /srv/homeassistant

  15. sudo chown homeassistant:homeassistant -R /srv/homeassistant

  16. cd /srv/homeassistant

  17. /usr/local/bin/python3.7 -m venv .

  18. source bin/activate

  19. pip install wheel homeassistant

20a. ** Note I chose to run hass first time to see all the installation messages.**

20b. sudo systemctl start home-assistant@homeassiith Python 3.7.3

From all the posts on this subject I’ve seen these seem to be the most effective.

Again a big thank you to @anon34565116

7 Likes

I.agree with both phrases.

2 Likes

I am happy to assist.
It helps I am a former Unix administrator and still work some in Linux now.

That is your chance. He is the man. :smiley:

I’ve no doubt this subject will be revisited as we come closer to Python 3.5 deprecation time. At least we now have a definitive set of instructions that will work on a Hass installation in a venv.

1 Like