Python 3.6 upgrade of a virtualenv

Well @anon34565116 to the rescue AGAIN !!!

Followed your install instructions and with a few minor mods and permission issues that I resolved, my HA venv is now up and running on Python 3.7.3 and my HA config prior to the Python upgrade is exactly as it was.

Thanks to anyone else who contributed to this post. I do understand that each user has their preferred platform for HA but I find the venv works for me and I’ve now achieved this now upgrading to Python 3.7.3

1 Like

The @anon34565116 procedure is based in hassbian, but it not for hassbian, right? I need to update raspbian. Just asking to avoid mistakes.

@ConcordGE , could you please tell us what were the minor mods and issues you faced it?

It’s an installation of Home Assistant on Raspbian in a venv as per these instructions https://www.home-assistant.io/docs/installation/raspberry-pi/

I needed to use sudo in lines 10 and 11. I needed to remove the “ at the end of line 15.

When updating to 0.94.1 I had permission issues which pip advised me that I needed to change.

Meant to say your post was very helpful.

I have the feeling, that HomeAssistant is running slower and needs more time to start with python 3.7. And HomeKit doesn‘t work. I got it running only one time after delaying HomeKit startup. Does anybody also have problems? Its running without problems with python 3.5. I use Deconz and Fritzbox integrations.

You are correct.

I was also able to upgrade the venv using those steps with the following additions:
Step 1: I had to also add libffi-dev
Steps 12/13/17: added sudo (als already mentioned above)
Step 19: had to add pip3 install mysqlclient because my Home Assistant installation uses a MySQL database for the recorder component.

3 Likes

I already had that installed from an earlier installation issue. I think it is needed for zwave?
I constructed that list after I knew I had a working solution. Sorry for the errors.

We now have a tried, tested and working method of upgrading Python in the venv.

My own Hass install is on a Raspberry Pi 3 running Raspbian Stretch Lite.

Clearly there is no need to wait for the impending release of Raspbian Buster to have access to the latest version of Python running in a virtual environment. It can be easily upgraded with a currently installed version of Hass.

Nice work @anon34565116

1 Like

@ConcordGE you are very welcome.
I think I was able to edit my original list to correct errors.

Guys, I tryed to updated it, but I think I will need the help of a good soul with more knowledge than me to complete it.

  1. After step 19, it said that I was using pip 19.0.3, and that I should upgrade it to 19.1.1. Than I typed “pip install --upgrade pip” inside the venv, but it returned the folowing message: Could not install packages due to EnvironmentError: [Errno 13] Permission denied: ‘/srv/homeassistant/bin/pip’ Consider using the ‘–user’ option or check the permissions.

  2. Tryed to start HA with step 20b “sudo systemctl start [email protected]”, but it doesn’t start.

  3. Typing “python3 --version” , returns 3.5.3. WEIRD, since I did all the steps. (Also tryed a reboot).

I should say that I run the commands running “pi” user, since it is the way that I usually update HA and the user which I can login by ssh. It may be related to this. So now I am stuck needing some help from someone with more knowledge. Arghh!

EDIT:
I usually do the following to get into the venv and update HA:

pi@hassbian:~ $ sudo -u homeassistant -H -s
homeassistant@hassbian:/home/pi $ source /srv/homeassistant/bin/activate
(homeassistant) homeassistant@hassbian:/home/pi $

Inside the venv, if I type “python3 --version”, I get 3.7.3. Out of the venv, 3.5.3. I don’t know if there is a problem with this.
My problem may be related to step 15 “sudo chown homeassistant:homeassistant -R /srv/homeassistant”, explaining why I can’t run homeassistant running “pi” user. But I don’t know how to solve the problem. I don’t wanna mess things, so I will wait for a tip. Thanks.

Here were my steps on raspbian:

# As root
apt-get update
apt-get install -y 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 libffi-dev
wget https://www.python.org/ftp/python/3.7.3/Python-3.7.3.tgz
tar zxf Python-3.7.3.tgz
cd Python-3.7.3/
./configure --prefix=/usr
make -j 4
make altinstall
systemctl stop home-assistant
# Switch to Home Assistant User
sudo su - homeassistant
cd /home/homeassistant/
python3.7 -m venv homeassistant_venv
source /home/homeassistant/homeassistant_venv/bin/activate
pip install --upgrade pip
wget https://raw.githubusercontent.com/home-assistant/home-assistant/master/requirements_all.txt -O requirements_all.txt
# This takes hours to finish and you may need to install additional failed dependecies if you get errors
pip install -r requirements_all.txt
pip install mysqlclient
pip install homeassistant
# Go back to root
exit
# edit systemd service unit for new virtualenv
#vim /etc/systemd/system/home-assistant.service
#"ExecStart=/home/homeassistant/homeassistant_venv/bin/hass -c "/home/homeassistant/.homeassistant"
systemctl daemon-reload
systemctl start home-assistant

Your quote sudo -u homeassistant -H -s changes from the pi user to the homeassistantuser. I expect your configuration folder is/home/homeassistant/.homeassistant` and owned by that user.

For your first issue, if you were in the venv, it should work as the 1homeassistant1 user.

For your second issue, are you sure step 19 finished with no errors? in the venv as the homeassistant user you should be able to run home assistane manually by typeing hass.

For your third issue, if you are outside the venv the proper commane would be python3.7 --version You are seeing the older installer version.

In the venv python --version and python3 --version should bothe return the proper value.

Yes, my configuration is at: /home/homeassistant/.homeassistant

Could not install packages due to an EnvironmentError: [Errno 13] Permission denied: '/srv/homeassistant/bin/pip'
Consider using the `--user` option or check the permissions.

You are using pip version 19.0.3, however version 19.1.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
(homeassistant) homeassistant@hassbian:/home/pi $

As you see above, I believe that I am running as homeassistant user inside the venv.

For #2, nothing wrong called my attention. Can I run it again?

For #3, OK python3.7 returns 3.7.3.

Try re-running Step 15 again to make sure the homeassistant user owns all the files in srv/homeassistant.

(homeassistant) homeassistant@hassbian:/home/pi $ hass
bash: hass: command not found

IT looks like you are in the venv & homeassistant is not installed.

Step 15 - 19 install homeassistant.

Since you are already in a venv type deactivate first to exit it.

1 Like

The hint is in what pip advises you to do. Use —user. Once that’s done, sort out owner/permissions issues, update to the latest version of Hass and you’ll find you’re back up and running with Python 3.7.3 and the latest version of Hass.

1 Like

Check your Line 15. Drop the “ at the end of the line

Got it to work running steps 15 to 19 again, but as homeassistant user. I run as pi before, that was the problem. Running now 0.94.2 with python 3.7.3 being reported in system health.
I could see some errors in the log after running “hass” that I will see how it goes and report back if needed.
THANK YOU VERY MUCH for your help. And also everybody that helped to fine tune the code. I could not achieve this alone. There is always a lot to learn.