Notes on Ubuntu (Linux) computing

Brief notes on installation, setup and other tasks in the Ubuntu world

Install CherryPy on Ubuntu 12.04

leave a comment »

CherryPy “is a pythonic, object-oriented web framework”. My goal is to use the package to make a simple desktop, browser-based application for looking at the output of statistical inference routines I’ve developed elsewhere — we’ll see if this works (I’m not sure yet).

In any case, the first step is to install with pip:

sudo pip install CherryPy

This should install without issue. There are tutorial scripts located at /usr/local/lib/python2.7/dist-packages/cherrypy/tutorial/ that you should be able to run. For example, the `hello world’ example can be started typing the following at you terminal:

python /usr/local/lib/python2.7/dist-packages/cherrypy/tutorial/

This will start up the web service and the resulting output can be seen in your browser by going to http://localhost:8080. To exit, close the web browser and use a Cntrl-C at the terminal to stop the server.

As I said above, I’d like to be able to read the contents of local files and display them in a browser. If a local file is called numbers.dat and contains the following:


We can use the following script to display the contents of the above file:

#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8

"""A super simple example of reading a file and displaying results with

import cherrypy

class ReadFile(object):
    def index(self):
        page = "<html><body>\n"
        page += "<p>Read file: <i>numbers.dat</i></p>\n"

        with open("numbers.dat", "r") as f:
            for line in f.readlines():
                    col1, col2 = line.strip().split(',')
                    page += "<p>{:s} -- {:s}</p>\n".format(col1, col2)

        page += "</body></html>"

        return page = True

# start CherryPy

For more detailed documentation and tutorials, see the CherryPy website.


Written by Chris S

January 23, 2014 at 9:49 pm

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: