home-assistant.github.io/getting-started/installation-virtualenv/index.html
2016-05-17 19:57:02 +00:00

337 lines
No EOL
16 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!doctype html>
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]> <html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!--> <html> <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>Installation in virtualenv - Home Assistant</title>
<meta name="author" content="Paulus Schoutsen">
<meta name="description" content="Instructions how to install Home Assistant in a virtual environment.">
<meta name="viewport" content="width=device-width">
<link rel="canonical" href="https://home-assistant.io/getting-started/installation-virtualenv/">
<meta property="fb:app_id" content="338291289691179">
<meta property="og:title" content="Installation in virtualenv">
<meta property="og:site_name" content="Home Assistant">
<meta property="og:url" content="https://home-assistant.io/getting-started/installation-virtualenv/">
<meta property="og:type" content="website">
<meta property="og:description" content="Instructions how to install Home Assistant in a virtual environment.">
<meta property="og:image" content="https://home-assistant.io/images/home-assistant-logo-2164x2164.png">
<meta name="twitter:card" content="summary">
<meta name="twitter:site" content="@home_assistant">
<meta name="twitter:title" content="Installation in virtualenv">
<meta name="twitter:description" content="Instructions how to install Home Assistant in a virtual environment.">
<meta name="twitter:image" content="https://home-assistant.io/images/home-assistant-logo-2164x2164.png">
<link href="/stylesheets/screen.css" media="screen, projection" rel="stylesheet">
<link href="/atom.xml" rel="alternate" title="Home Assistant" type="application/atom+xml">
<link rel='shortcut icon' href='/images/favicon.ico' />
<link rel='icon' type='image/png' href='/images/favicon-192x192.png' sizes='192x192' />
</head>
<body >
<header>
<div class="grid-wrapper">
<div class="grid">
<div class="grid__item three-tenths lap-two-sixths palm-one-whole ha-title">
<a href="/" class="site-title">
<img width='40' src='/demo/favicon-192x192.png'>
<span>Home Assistant</span>
</a>
</div>
<div class="grid__item seven-tenths lap-four-sixths palm-one-whole">
<nav>
<input type="checkbox" id="toggle">
<label for="toggle" class="toggle" data-open="Main Menu" data-close="Close Menu"></label>
<ul class="menu pull-right">
<li><a href='/getting-started/'>Getting started</a></li>
<li><a href='/components/'>Components</a></li>
<li><a href='/cookbook/'>Examples</a></li>
<li><a href="/developers/">Developers</a></li>
<li><a href="/blog/">Blog</a></li>
<li><a href="/help/">Need help?</a></li>
</ul>
</nav>
</div>
</div>
</div>
</header>
<div class="grid-wrapper">
<div class="grid grid-center">
<div class="grid__item two-thirds lap-one-whole palm-one-whole">
<article class="page">
<header>
<h1 class="title indent">
Installation in Virtualenv
</h1>
</header>
<hr class="divider">
<p>There are several reasons why it makes sense to run Home Assistant in a virtual environment. A <a href="https://virtualenv.pypa.io/en/latest/">virtualenv</a> encapsulates all aspect of a Python environment within a single directory tree. That means the Python packages you install for Home Assistant wont interact with the rest of your system and vice-versa. It means a random upgrade for some other program on your computer wont break Home Assitant, and it means you dont need to install Python packages as root.</p>
<p>Virtualenvs are pretty easy to setup. This example will walk through one method of setting one up (there are certainly others). Well be using Debian in this example (as many Home Assistant users are running Raspbian on a Raspberry Pi), but all of the Python related steps should be the same on just about any platform.</p>
<h2><a class="title-link" name="step-0-install-some-dependencies" href="#step-0-install-some-dependencies"></a> Step 0: Install some dependencies</h2>
<div class="highlighter-coderay"><div class="CodeRay">
<div class="code"><pre>$ sudo apt-get update
$ sudo apt-get upgrade
$ sudo apt-get install python-pip python3-dev
$ sudo pip install --upgrade virtualenv
</pre></div>
</div>
</div>
<h2><a class="title-link" name="step-1-create-a-home-assistant-user" href="#step-1-create-a-home-assistant-user"></a> Step 1: Create a Home Assistant user</h2>
<p>This step is optional, but its a good idea to give services like Home Assistant their own user. It gives you more granular control over permissions, and reduces the exposure to the rest of your system in the event there is a security related bug in Home Assistant. This is a reasonably Linux oriented step, and will look different on other operating systems (or even other Linux distributions).</p>
<div class="highlighter-coderay"><div class="CodeRay">
<div class="code"><pre>$ sudo adduser --system hass
</pre></div>
</div>
</div>
<p>Home Assistant stores its configuration in <code>$HOME/.homeassistant</code> by default, so in this case, it would be in <code>/home/hass/.homeassistant</code></p>
<p>If you plan to use a Z-Wave controller, you will need to add this user to the <code>dialout</code> group</p>
<div class="highlighter-coderay"><div class="CodeRay">
<div class="code"><pre>$ sudo usermod -G dialout -a hass
</pre></div>
</div>
</div>
<h2><a class="title-link" name="step-2-create-a-directory-for-home-assistant" href="#step-2-create-a-directory-for-home-assistant"></a> Step 2: Create a directory for Home Assistant</h2>
<p>This can be anywhere you want. AS example we put it in <code>/srv</code>. You also need to change the ownership of the directory to the user you created above (if you created one).</p>
<div class="highlighter-coderay"><div class="CodeRay">
<div class="code"><pre>$ sudo mkdir /srv/hass
$ sudo chown hass /srv/hass
</pre></div>
</div>
</div>
<p>## <a class="title-link" name="step-3-become-the-new-user" href="#step-3-become-the-new-user"></a> Step 3: Become the new user</p>
<p>This is obviously only necessary if you created a <code>hass</code> user, but if you did, be sure to switch to that user whenever you install things in your virtualenv, otherwise youll end up with mucked up permissions.</p>
<div class="highlighter-coderay"><div class="CodeRay">
<div class="code"><pre>$ sudo su -s /bin/bash hass
</pre></div>
</div>
</div>
<p>The <code>su</code> command means switch user. We use the -s flag because the <code>hass</code> user is a system user and doesnt have a default shell by default (to prevent attackers from being able to log in as that user).</p>
<h2><a class="title-link" name="step-4-set-up-the-virtualenv" href="#step-4-set-up-the-virtualenv"></a> Step 4: Set up the virtualenv</h2>
<p>All this step does is stick a Python environment in the directory were using. Thats it. Its just a directory. Theres nothing special about it, and it is entirely self-contained.</p>
<p>It will include a <code>bin</code> directory, which will contain all the executables used in the virtualenv (including hass itself). It also includes a script called <code>activate</code> which we will use to activate the virtualenv.</p>
<div class="highlighter-coderay"><div class="CodeRay">
<div class="code"><pre>$ virtualenv -p python3 /srv/hass
</pre></div>
</div>
</div>
<h2><a class="title-link" name="step-5-activate-the-virtualenv" href="#step-5-activate-the-virtualenv"></a> Step 5: Activate the virtualenv</h2>
<div class="highlighter-coderay"><div class="CodeRay">
<div class="code"><pre>$ source /srv/hass/bin/activate
</pre></div>
</div>
</div>
<p>After that, your prompt should include <code>(hass)</code>.</p>
<h2><a class="title-link" name="step-6-install-home-assistant" href="#step-6-install-home-assistant"></a> Step 6: Install Home Assistant</h2>
<p>Once your virtualenv has been activated, you dont need to <code>sudo</code> any of your <code>pip</code> commands. <code>pip</code> will be installing things in the virtualenv, which the <code>hass</code> user has permission to modify.</p>
<div class="highlighter-coderay"><div class="CodeRay">
<div class="code"><pre>(hass)$ pip3 install --upgrade homeassistant
</pre></div>
</div>
</div>
<p>And thats it… you now have Home Assistant installed, and you can be sure that every bit of it is contained in <code>/srv/hass</code>.</p>
<h2><a class="title-link" name="finally-run-home-assistant" href="#finally-run-home-assistant"></a> Finally… Run Home Assistant</h2>
<p>There are two ways to launch Home Assistant. If you are <strong>in</strong> the virtualenv, you can just run <code>hass</code> and it will work as normal. If the virtualenv is not activated, you just use the <code>hass</code> executable in the <code>bin</code> directory mentioned earlier. There is one caveat… Because Home Assistant stores its configuration in the users home directory, we need to be the user <code>hass</code> user or specify the configuration with <code>-c</code>.</p>
<div class="highlighter-coderay"><div class="CodeRay">
<div class="code"><pre>$ sudo -u hass -H /srv/hass/bin/hass
</pre></div>
</div>
</div>
<p>The <code>-H</code> flag is important. It sets the <code>$HOME</code> environment variable to <code>/home/hass</code> so <code>hass</code> can find its configuration.</p>
<h2><a class="title-link" name="upgrading-home-assistant" href="#upgrading-home-assistant"></a> Upgrading Home Assistant</h2>
<p>Upgrading Home Assistant is simple, just repeat steps 3, 5 and 6.</p>
<h2><a class="title-link" name="starting-home-assistant-on-boot" href="#starting-home-assistant-on-boot"></a> Starting Home Assistant on boot</h2>
<p>The <a href="/getting-started/autostart/">autostart instructions</a> will work just fine, just be sure to replace <code>/usr/bin/hass</code> with <code>/srv/hass/bin/hass</code> and specify the <code>hass</code> user where appropriate.</p>
<h2><a class="title-link" name="installing-python-openzwave" href="#installing-python-openzwave"></a> Installing python-openzwave</h2>
<p>If you want to use Z-Wave devices, you will need to install <code>python-openzwave</code> in your virtualenv. This requires a small tweak to the instructions on home-assistant.io</p>
<p>Install the dependencies as normal (Note: you will need to do this as your normal user, since <code>hass</code> isnt a sudoer).</p>
<div class="highlighter-coderay"><div class="CodeRay">
<div class="code"><pre>$ sudo apt-get install cython3 libudev-dev python3-sphinx python3-setuptools
</pre></div>
</div>
</div>
<p>Then, activate your virtualenv (steps 3 and 5 above) and upgrade cython.</p>
<div class="highlighter-coderay"><div class="CodeRay">
<div class="code"><pre>(hass)$ pip3 install --upgrade cython
</pre></div>
</div>
</div>
<p>Finally, get and install <code>python-openzwave</code>.</p>
<div class="highlighter-coderay"><div class="CodeRay">
<div class="code"><pre>(hass)$ mkdir /srv/hass/src
(hass)$ cd /srv/hass/src
(hass)$ git clone https://github.com/OpenZWave/python-openzwave.git
(hass)$ cd python-openzwave
(hass)$ git checkout python3
(hass)$ PYTHON_EXEC=`which python3` make build
(hass)$ PYTHON_EXEC=`which python3` make install
</pre></div>
</div>
</div>
</article>
</div>
<aside id="sidebar" class="grid__item one-third lap-one-whole palm-one-whole">
<div class="grid">
<section class="aside-module grid__item one-whole lap-one-half">
<div class='edit-github'><a href='https://github.com/home-assistant/home-assistant.io/tree/master/source/getting-started/installation-virtualenv.markdown'>Edit this page on GitHub</a></div>
<div class='section'>
<h1 class="title delta">Getting Started Guide</h1>
<ul class='divided sidebar-menu'>
<li>
<a href='/getting-started/'>Installation </a>
<ul>
<li><a href='/getting-started/installation-raspberry-pi/'>Raspberry Pi </a></li>
<li><a href='/getting-started/installation-raspberry-pi-all-in-one/'>Raspberry Pi All-In-One Installer </a></li>
<li><a href='/getting-started/installation-docker/'>Docker </a></li>
<li><a href='/getting-started/installation-synology/'>Synology NAS </a></li>
<li><a class='active' href='/getting-started/installation-virtualenv/'>VirtualEnv Linux </a></li>
<li><a href='/getting-started/troubleshooting/'>Troubleshooting </a></li>
</ul>
</li>
<li>
Configuration
<ul>
<li><a href='/getting-started/configuration/'>Configuration.yaml </a></li>
<li><a href='/getting-started/devices/'>Setting up devices </a></li>
<li><a href='/getting-started/customizing-devices/'>Customizing devices and services </a></li>
<li><a href='/getting-started/presence-detection/'>Presence Detection </a></li>
<li><a href='/getting-started/troubleshooting-configuration/'>Troubleshooting </a></li>
</ul>
</li>
<li>
<a href='/getting-started/automation/'>Automation </a>
<ul>
<li><a href='/getting-started/automation-create-first/'>Tutorial </a></li>
<li><a href='/getting-started/automation-trigger/'>Triggers </a></li>
<li><a href='/getting-started/automation-condition/'>Conditions </a></li>
<li><a href='/getting-started/automation-action/'>Actions </a></li>
<li><a href='/getting-started/automation-templating/'>Templates </a></li>
</ul>
</li>
<li>
<a href='/getting-started/scripts/'>Scripts </a>
<ul>
<li><a href='/getting-started/scripts-service-calls/'>Service Calls </a></li>
<li><a href='/getting-started/scripts-conditions/'>Conditions </a></li>
</ul>
</li>
<li>
<a href='/getting-started/autostart/'>Auto-start Home Assistant </a>
<ul>
<li><a href='/getting-started/autostart-systemd/'>Linux - systemd </a></li>
<li><a href='/getting-started/autostart-upstart/'>Linux - Upstart </a></li>
<li><a href='/getting-started/autostart-macos/'>OS X </a></li>
<li><a href='/getting-started/autostart-synology/'>Synology NAS </a></li>
</ul>
</li>
<li><a href='/topics/'>Advanced Topics</a></li>
<li><a href='/getting-started/android/'>Add to Android Homescreen </a></li>
</ul>
</div>
</section>
</div>
</aside>
</div>
</div>
<footer>
<div class="grid-wrapper">
<div class="grid">
<div class="grid__item">
<div class="copyright">
<a rel="me" href='https://twitter.com/home_assistant'><i class="icon-twitter"></i></a>
<a rel="me" href='https://github.com/home-assistant/home-assistant'><i class="icon-github"></i></a>
<div class="credit">
Website powered by <a href='http://jekyllrb.com/'>Jekyll</a> and the <a href='https://github.com/coogie/oscailte'>Oscalite theme</a>.<br />
Hosted by <a href='https://pages.github.com/'>GitHub</a> and served by <a href='https://cloudflare.com'>CloudFlare</a>.
</div>
</div>
</div>
</div>
</div>
</footer>
<script>
var _gaq=[['_setAccount','UA-57927901-1'],['_trackPageview']];
(function(d,t){var g=d.createElement(t),s=d.getElementsByTagName(t)[0];
g.src=('https:'==location.protocol?'//ssl':'//www')+'.google-analytics.com/ga.js';
s.parentNode.insertBefore(g,s)}(document,'script'));
</script>
</body>
</html>