How to Install Bottle on the Raspberry Pi

You will need easy_install to install bottle. In order to install easy_install, you will need Distribute:

curl -O  
sudo python  
sudo easy_install bottle

Now let's test it out. Open up nano or another text editor:

sudo nano

and copy and past the hello word script from

<span class="kn">from</span> <span class="nn">bottle</span> <span class="kn">import</span> <span class="n">route</span><span class="p">,</span> <span class="n">run</span><span class="p">,</span> <span class="n">template</span>

<span class="nd">@route</span><span class="p">(</span><span class="s">'/hello/&lt;name&gt;'</span><span class="p">)</span>  
<span class="k">def</span> <span class="nf">index</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s">'World'</span><span class="p">):</span>  
    <span class="k">return</span> <span class="n">template</span><span class="p">(</span><span class="s">'&lt;b&gt;Hello {{name}}&lt;/b&gt;!'</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="n">name</span><span class="p">)</span>

<span class="n">run</span><span class="p">(</span><span class="n">host</span><span class="o">=</span><span class="s">'localhost'</span><span class="p">,</span> <span class="n">port</span><span class="o">=</span><span class="mi">8080</span><span class="p">)</span>

Let's execute the script:


On my regular compute I went to but was unable to load it (I received the IP address from ifconfig)

On my RPi I executed the following:

curl http://localhost:8080/hello/matthew

and received the expected result: <b>Hello matthew</b>!. After looking around, I learned that the host cannot be kept to 'localhost', but should instead be set to ''. Change the hello world script to:

from bottle import route, run, template

def index(name='World'):  
    return template('<b>Hello {{name}}</b>!', name=name)

run(host='', port=8080, reloader=True)

And it works.

Update: I've had problems with Bottle turning itself off after some period of time. Google suggested installing the meinheld server via:

sudo apt-get <em>install</em> python-<em>pip</em>  
sudo pip install meinheld

and then instruct Bottle to use the server in the run() function:

 run(server="meinheld", host='', port=8080, reloader=True)


Add Comment




Are you human? + ten = 15