Quantcast
Channel: Configuration - Home Assistant Community
Viewing all articles
Browse latest Browse all 103366

Upgrading HomeAssistant Core in a Python VE

$
0
0

Hi,

Installing or Upgrading Home Assistant to the Latest & Greatest in a Python Virtual Environment, may be tricky. So I Thought I’d create a post after I’ve struggled through it enough times now.

Hopefully this helps other members.

In summary there is a couple of steps involved, but from a High Level, this is whats requireed:

  1. Ensure you have a Supported Python version for the latest build. Currently for Build 2021.12.10, the earliest version of Python is 3.9.1.
  2. Upgrade the Python on your Platform (I am using Ubuntu 18.04, pressume its the same for later versions or other deebian variants).
  3. Backup your current Python Packages
  4. Upgrade your Python Environment
  5. Rebuild Homeassistant to run in the new Python Environment
  6. Upgrade Homeassistant on the new Python Environment
  7. Check for other breeaking changes (For example the SQL Lite version).

So in summary here is what I did to upgrade my HASS core deployment on Ubuntu to the latest:

a) Log into the Shell.
b) Check Python Version:

python --version
python3 --version

c) If you have a Python version that is supported (3.9.1 at the time of writing this) or above then skip until step i) Otherise continue to Upgrade Python as follow:

wget https://www.python.org/ftp/python/3.9.1/Python-3.9.1.tgz
tar -xzf Python-3.9.1.tgz
cd Python-3.9.1
./configure
make -j 4
sudo make install

d) Backup Current Python Packages:

cd /home/homeassistant/.homeassistant
sudo -u homeassistant -H -s
source /srv/homeassistant/bin/activate
pip3 freeze –local > requirements.txt

e) Backup your Existing HASS folder (for Justin…Justin Case)

sudo systemctl stop home-assistant@homeassistant
sudo mv homeassistant homeassistandold
sudo mkdir homeassistant
sudo chown -R homeassistant:homeassistant homeassistant

f) Install Hass dependancies on the New Version of Python

cd /srv/homeassistant/lib
sudo -u homeassistant -H -s
cd /srv/homeassistant
sudo python3.9 -m venv .
source /srv/homeassistant/bin/activate
cd /home/homeassistant/.homeassistant
pip3 install -r requirements.txt

g) If you get an Error about not having access to some Python Libraries (e.g. ERROR: Could not install packages due to an EnvironmentError: [Errno 13] Permission denied: '/srv/homeassistant/lib/python3.9/site-packages/six.py’) do the following (which sets the correct perssions and re-runs the install):

cd /srv
sudo chown -R homeassistant:homeassistant homeassistant
cd /home/homeassistant/.homeassistant
pip3 install -r requirements.txt

h) Finalise the Hass Install:

pip3 install homeassistant
sudo systemctl start home-assistant@homeassistant.service

i) Upgrade Hass
At this point, Hass should be running on a supported version of Python,to Upgrade Hass to the latest version do the following:
Start a New SSH session, and run:

source /srv/homeassistant/bin/activate
sudo systemctl stop home-assistant@homeassistant.service
pip3 install --upgrade homeassistant
sudo systemctl start home-assistant@homeassistant.service

Once all of this is done, HASS should be the latest version, Python should be a supported version, and all should be good.

Once you have reached this point, wait for any recorder/db checks & rebuilds, and wait until Home Assistant becomes available again, you can monitor the progress under /home/homeassistant/.homeassistant/home-assistant.log

sudo nano /home/homeassistant/.homeassistant/home-assistant.log

HOWEVER…

If you run into an Error, where the version of SQL Lite is not supported then do the following:
j) Install & configure SQL Lite:
Start on a Fresh SSH session

sudo systemctl stop home-assistant@homeassistant.service
wget https://sqlite.org/2021/sqlite-autoconf-3360000.tar.gz
tar -xvf sqlite-autoconf-3360000.tar.gz
./configure
make
sudo make install

Once the supported version of SQL lite is downloaded & installed, you will probably still have the error when trying to start Home Assistant, reason for this is because the SQL Lite install happens to the default location (/usr/local/lib/), and is not in a place where HomeAssistant expects it to be (/usr/lib/xxxx).

To correct this, you have to determine your system type (For Example, a normal x86/x64 PC will be x86_64-linux-gnu, and a Raspberry PI it would be arm-linux-gnueabihf), and then copy the files from the default install to the exepceted folder.

This is done by executing the follwing for a x86 or x64 Ubuntu system:

sudo cp /usr/local/lib/*sql* /usr/lib/x86_64-linux-gnu/

Or by executing the following for a Raspberry Pi ARM system:

sudo cp /usr/local/lib/*sql* /usr/lib/arm-linux-gnueabihf/

Once copied across, we need to set the permissions on the above directories
For a x86 or x64 Ubuntu system:

sudo chmod a+x /usr/lib/x86_64-linux-gnu/*sql*

For a Raspberry Pi ARM system:

sudo chmod a+x /usr/lib/arm-linux-gnueabihf/*sql*

Once this is done, you can Start the Hass Instance:

sudo systemctl start home-assistant@homeassistant.service

And then monitor the statup again by:

sudo nano /home/homeassistant/.homeassistant/home-assistant.log

Hopefully this helps!

1 post - 1 participant

Read full topic


Viewing all articles
Browse latest Browse all 103366

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>