Installing Home Assistant in a virtual environment there are pluses and minuses

So following recommendations for my Ubuntu 16.04 system, TheI installed Home Assistant in a virtual environment. Recently, I’ve been unable to upgrade my Hass since it’s running Python 3.5.2. So today I decided to upgrade to Ubuntu 17.10 which runs Python 3.6. Much to my surprise after the upgrade finished, I discovered that the upgrade did not affect my virtual environment. I still could not update Hass. I guess I should have known that, but I didn’t. It turns out I need to delete my virtual environment and re-install it to update Hass. It doesn’t look that hard, but had I known I might not have used a virtual environment.

I’m thinking you don’t understand the concept of the venv.

You previously created a venv with 3.5.2

Now you need to create one with 3.6.whatever.

Takes 2 minutes, no drama.

2 Likes

I would downvote this if I could :slight_smile:
+1 for python virtual env

Yes, it’s just a minor pain, but I’m not at all sure that the virtual environment is providing with anything I really need. I’m running Hass in a intel Atom based system. Nothing else is running on it. I have other small servers ITX based available if i need them. So I’m sticking with my original statement. My only purpose in posting is to make others pause a second or two before before installing this way if they don’t really need to. That’s what I did.

Yes, it’s just a minor pain, but it comes under the heading of rework to me. I’m not at all fond of the concept of rework, It just gives more chances to mess something up. Moreover I’m not at all sure that the virtual environment is providing with any benefits I need. I’m running Hass in a intel Atom based system. Nothing else is running on it. I have other small servers ITX based available if i need them. So I’m sticking with my original statement. My purpose in posting is to suggest others pause a second or two before before installing this way if they don’t really need to. That’s what I did.

I don’t think you are aware of the potential problems that installing python programs natively can bring.

Take, for instance, appdaemon. If you install appdaemon on top of HA without a venv, HA will break. There will be no warning, it will just stop running. You can then re-install HA, and it will work, but then there is the possibility that appdaemon will break.

For appdaemon, you could substitute many other python programs, that will cause your system to go down.

Comparing the problems that this can cause, spending a few minutes creating a virtual environment is time well spent.

2 Likes

Put your Home Assistant instance in a Docker container. You’ll have sort of an virtual environment, that doesn’t polute your host system with douzends of python versions.

1 Like

This is bad advice and it’s unfortunate that the clickbait title will make a lot of people read it.

4 Likes

I know that this is unpopular opinion here, but I think that all those virual environments and gazilion docker containers should be for testing, tinkering and developing only. True reliable home automation solution should be in form of something like hass.io with necessary add-ons on machine dedicated only for HA. People are runing godknowswhat on their puny RPi and they are complaining when something went wrong…

2 Likes

Are you aware that hass.io is solely based on Docker? I have exactly two Docker containers on my Raspberry Pi 3 running Raspbian:

  • home assistant
  • home bridge

All other software that is available via apt (the Raspbian/Debian package manager) is installed this way, like MariaDB and Mosquitto. But when it comes to additional package managers like pip, npm or cpan - i head for Docker to keep the host system as clean as possible.

However: This is not a configuration topic, but should be in General Discussion / Religion.

1 Like

Yes, I am aware of that. But you know what I meant.
And yes, this is General Discussion ideed.

This is absolutely correct, but not everyone runs on a raspberry pi, and not everything fits within the add-ons structure. The beauty of HA is that it is just a Python program and can be run anywhere that Python has been installed.

However, it also comes with all the package dependency problems of installing multiple Python programs, which is what a virtual environment or by a different approach docker, achieves. Saying they should be only used for testing or developing doesn’t really acknowledge the problem.

1 Like

Running in a Python virtual environment doesn’t stop it being on a machine dedicated to Home Assistant.

You mean like when they install Hass.io with a bunch of add-ons, on a RPi? :wink:

Also, in this case, clearly not a Pi since they’re running Ubuntu 16.04.

1 Like

May be its just my perception of things, but it seems like to me that majority problems here are because of virtual environments and docker… :grinning:

Well, strictly you’re not wrong. Most posts here relate to people running Home Assistant on Hass.io (Docker), Hassbian (python virtual environment), or the old AIO installer (virtual environment again).

On that basis, most problems relate to Docker or virtual environments :stuck_out_tongue:

Personally, anybody installing Home Assistant manually outside of a venv is asking for problems, for all the reasons people have already posted. You either use a venv, or a Docker install (Hass.io or native).

:smiley:
I vote for clean hass.io with some necessary add-ons on something other than RPi. :slight_smile: To me, it proves to be the most reliable and hassle-free solution so far, but others millage may vary of course…

I don’t use appdaemon. Haven’t had issues running python apps or python programs without it.

You haven’t had a problem yet, but its an ongoing threat you will need to be aware of.

The problem with your initial statement was that you declared that virtual environments didn’t provide any benefits, when in fact they do provide protection for known situations. Those situations will cause a sudden loss of all HA functionality. Anyone following your advice would be exposing themselves to this.

If you are willing to take that risk, it is up to you, but I don’t think you should be encouraging others to do so, without at least mentioning the risk itself and why it doesn’t apply to you.

1 Like

So, I’d be willing to delete this entire thread. Maybe my entire complaint is about documentation. The fact that a virtual environment provides benefits like you are describing doesn’t seem to be documented anywhere. Neither is the fact that you need to upgrade/replace your virtual environment when you do a system upgrade. In fact how to update/upgrade your virtual environment isn’t documented either (or maybe I just haven’ found it). There are several posts with slightly different approaches but the one listed at the bottom of this thread appears to have issues with zwave.

The benefits are very briefly mentioned in the docs, but yes, there’s an assumption people will follow the links to the Python docs. Maybe that needs addressed.

I’ve got the upgrade steps on a blog post, though they’re not so much upgrade and more build a fresh venv. That process does work for Z-Wave :wink:

2 Likes