How to upgrade virtualenv (virtual environment) to Python 3.7 on Ubuntu ( Ubuntu server 18.04 )

Thanks for this. Having the same missing front-end issue on FreeNAS. Installing it manually gets everything working again!

Thank you very much for this. Looks like I’m going to need to upgrade as well. As comfortable as I generally feel in HA, I don’t feel as comfortable in unix. I can install, download updates, follow instructions, etc.

I did my install about a year ago using these instructions
(as another user)

So, if I generally follow your instructions I will have to do some steps as the Home Assistant User, right?

EDIT: Couple of questions
So If I did this

sudo -u homeassistant -H -s
cd /srv/homeassistant
python3 -m venv .
source bin/activate

when I did my initial install, what folder do I need to backup (mv) to be safe?
/srv/homeassistant ?

Also, I think that this is what I’d do to upgrade if I’m running VENV as another user

sudo apt update
sudo apt install software-properties-common
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt install python3.7
sudo apt install python3.7-dev
sudo apt install python3.7-venv

cd /srv
sudo mkdir homeassistant (might not be needed, depends on path to previous install?)
sudo chown homeassistant:homeassistant homeassistant (might not be needed, depends on path to previous install?)

sudo -u homeassistant -H -s
cd /srv/homeassistant
python3.7 -m venv .
source bin/activate
pip install --upgrade pip (not sure if needed??)
python3.7 -m pip install homeassistant
pip install home-assistant-frontend

Does that look right?

1 Like

As I mentioned in my earlier post, if you have Ubuntu 18.x you can skip deadsnakes (lines 1 - 3).

I recommend you first update you system in general:
sudo apt update
sudo apt upgrade
If you want to use deadsnakes do lines 2, 3 and then 1.

The rest looks about right. Just note that once you have run source bin/activate, then your command line interface has been setup to automatically use python3.7 meaning you don’t have to specify 3.7 in any more of your commands (unless you run deactivate), so you would only need to enter pip install homeassistant.

1 Like


Thanks for this. I am using HA on ubuntu 18.04 installed in a virtual environment as user ‘homeassistant’. my config files are in /home/homeassistant/.homeassistant and i use an external mySQL database.

Below are the exact steps I took to install (I can take no credit for it as it is all the bits in the posts above put together!):

systemctl stop home-assistant@homeassistant

apt update

apt install python3.7

apt install python3.7-dev

apt install python3.7-venv

cd /srv

#cp homeassistant homeassistant_old ##edited below as it should be a mv

mv homeassistant homeassistant_old

mkdir homeassistant

chown homeassistant:homeassistant homeassistant

sudo -u homeassistant -H -s

cd /srv/homeassistant

python3.7 -m venv .

source bin/activate

pip install --upgrade pip

python3.7 -m pip install mysqlclient

python3.7 -m pip install homeassistant

pip install home-assistant-frontend


systemctl start home-assistant@homeassistant

journalctl -f -u home-assistant@homeassistant

I do log on as root so no sudo required.

Thanks for all the posts above that got me to this and I hope this helps anyone else with a standard Ubuntu install as user homeassistant in a virtenv



Just one Quick question, did you do a
cp homeassistant homeassistant_old


mv homeassistant homeassistant_old

mv homeassistant homeassistant_old

I agree that is what I would expect, I was just asking because in @markbajaj steps he listed cp vs mv. Figured if it was a typo he could fix his post to save others from messing up. or maybe he did do a cp, although, I’d expect that not to work. haha

1 Like

You are correct, I did a mv not a copy :slight_smile:

I’ll edit the post now :+1:



1 Like

Thanks for this great tutorial. Does anyone have similar instructions for CentOS or a similar rpm-based linux? I previously posted about the problem with deprecating Python 3.6 for CentOS, as there are no officially supported 3.7+ packages available yet, but no one has commented yet (see Python support on CentOS after version 3.6 deprecation).

Maybe check out this thread and this comment in particular which give you some ideas how to build from scratch:

I was dreading the upgrade and thanks to your hard work it was a breeze. Thank you.

1 Like

Just wanted to bump this up a bit. I finally got around to doing this tonight. Took 10 min or so and I had zero issues. I honestly was caught off guard by how well it went. Thank you very much for the easy to follow guide

One thing to note I had a few shell commands in my setup and could not figure out why they were not working anymore.

I have not fixed yet, but I’m pretty sure I need to change the command from

python3 /home/homeassistant/.homeassistant/python_scripts/


python3.7 /home/homeassistant/.homeassistant/python_scripts/

A big “Thank you!” to @Alexander_Stepanov and @markbajaj for their helpful instructions. I finally took the plunge and updated my production system from 0.89 to 0.103.2.

It was quite the leap but my test system was already running 0.103.2 (albeit with docker) so at least I knew the configuration changes I would need to make. What has caused me to procrastinate is that it the production system uses a venv and I wasn’t certain how to perform the python upgrade.

Anyway, the instructions helped me a great deal. The biggest glitch occurred when Home Assistant attempted to build the cryptography wheel and aborted. It referred to PEP 517 and after a search through the forum I found I needed to backtrack and do this:
sudo apt-get install libssl-dev
Afterwards, the second attempt to install Home Assistant ran without a problem.

Some more tweaking was needed to clean up my configuration file and then everything settled down to work nominally.

Thanks again!

1 Like

I’m trying to upgrade Python on my system (just installed a Fedora system that comes with Python 3.4.3) and have a silly question.

So I activated the environment and from within venv I try to run the first command

sudo apt update

Then I get a message about a password to the venv. Do I need to “logon” to this virtual environment? If yes, what’s the password? There was no step anywhere I can remember that asked me to create a password

The sudo command requires your userid password. You may not have a password for your homeassistant userid because you have not set a password.

whoami will show your userid.

Either set a password for your homeassistant user and put that userid into the sudoers group or exit back you your login userid and run apt commands from there.


Can I just thank you. These are more concise and complete directions that literally anywhere else that I have found.

1 Like

@Alexander_Stepanov I’m confused here, if you move the venv aren’t you just installing fresh HA here?

Basically, yes. But you’re pointing it to the same config folder, so it just starts up as if nothing happened. Same thing as when you upgrade a docker container.

Edit: “docket” —> “docker”

1 Like

my bad, i didn’t realised i installed in /srv/ that’s what confused me, thanks!