I just updated my venv install to the latest HA version and am seeing the warning about Python 3.8 being deprecated. I have searched around and found out that I need to rebuild my venv in order to fix this, but not sure I want to go through the hassle of this so I am wondering if there is a relatively easy way of moving from venv to supervised. I am currently running several custom components via HACS and I think this may be an issue but not sure. Any help would be appreciated.
Honestly, rebuilding the venv isn’t too bad.
Last time I did it (needed to upgrade Python) it was roughly this, and took 15 minutes:
Backup your entire HA directory (remember the .storage directory) first
Remove existing venv
Create new venv
Install HA into new venv
Copy backed up config to new HA
Start new HA
Definitely less work than converting to a much less stable supervised installation where you no longer have control over your HA installation, are forced to use a hard coded DNS, and can wake up any day to find your system unresponsive because of a botched update.
Home Assistant Container with Docker is another option. The Python is then integrated in the container with only your data native n the server.
@AaronCake Yes I suppose you are right. I built the venv from a tutorial and while I do understand the basics of how it runs I am not sure how to do all those steps you listed. Do you have a good tutorial recommendation for this?
I use this script to update, it checks for a new version of python, and if found makes a backup and a new venv. Be sure to run it once before you upgrade Python3. The steps inside somewhat explain whats going on, run from the directory where the script is stored as sudo i.e. sudo ./update-ha.sh:
#!/bin/bash BACKUPDIR=/mnt/Backups/Homeassistant cd /srv # Check current version of Python and upgrade or reinstall if [ "$(python3 --version)" == "$(cat .pythonver)" ]; then echo "Verified $(python3 --version), updating Home-Assistant." systemctl stop [email protected] cd homeassistant source bin/activate python3 -m pip install --upgrade homeassistant systemctl start [email protected] echo "Finished updates, starting Home-Assistant." else echo "Newer version of $(python3 --version) found, creating backup." systemctl stop [email protected] cp .pythonver homeassistant/ tar -zcf hass-srv.tar.gz homeassistant rm -rf homeassistant python3 -m venv homeassistant cd homeassistant source bin/activate python3 -m pip install homeassistant cd /srv chown homeassistant:homeassistant homeassistant -R systemctl start [email protected] python3 --version > .pythonver /bin/cp -f hass-srv.tar.gz $BACKUPDIR echo "Finished updates with $(cat .pythonver), starting Home-Assistant." fi
I didn’t write this, but I cannot find who to attribute it to.
Unfortunately I don’t really have a set of instructions written up, nor where to find one. As I don’t deal with Python venv everyday I just searched out the individual tasks.
That said I did just search it and found this:
Looks like a fairly good writeup of removing the old venv, loading newest Python version, and creating a new.
Just keep in mind that this is a fresh install of HA so if you have made any changes beyond configuration you will need to apply those to the new venv.
@AaronCake I found that one as well. Using that page and a few other sites I made myself a procedure that works. Here are the steps that worked for me:
Upgrading Python for VENV installs
This was for Python 3.9
Install new version of Python
sudo apt update sudo apt install software-properties-common sudo add-apt-repository ppa:deadsnakes/ppa sudo apt install python3.9 sudo apt install python3.9-dev sudo apt install python3.9-venv
Backup HA and install new VENV
mv /srv/homeassistant /srv/homeassistant_bkp
sudo mkdir /srv/homeassistant sudo chown homeassistant:homeassistant /srv/homeassistant
sudo -u homeassistant -H -s cd /srv/homeassistant python3.9 -m venv . source bin/activate
python3 -m pip install wheel pip3 install homeassistant
I had some issues with the WLED integration but found that there is a bug in HA CORE install that does not install a package called “packaging” Here is a reference to that issue: https://www.reddit.com/r/homeassistant/comments/qrs5cf/moving_venv_from_one_vm_to_another/
I just needed to manually install it with:
pip install packaging