Site5 - Built For Designers & Developers MENU
Home  ›  Python  ›  Python: How to install Bottle

Python: How to install Bottle

5 Comments

In this article, we will show you how to install Bottle.

Let’s start by making a folder we can download the stuff we need to.

mkdir ~/tmpdownload

Let’s move into that folder…

cd ~/tmpdownload

Let’s download the files and unzip them…

wget https://pypi.python.org/packages/source/b/bottle/bottle-0.11.6.tar.gz
tar xzf bottle-*.tar.gz && rm bottle-*.tar.gz

Now lets move into the folder that we unzipped…

cd b*

It’s time to do the install itself…

python2.6 setup.py install --user

Now lets move into our public_html folder so we can start adding the needed files…

cd ~/public_html

Lets create the htaccess file we are going to need…

nano .htaccess

Once Nano is open, paste the following…
AddHandler fcgid-script .fcgi
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.fcgi/$1 [QSA,L]

To save it, simply press Ctrl + X, Y then Enter.

Now lets make the fcgi file we need…

nano index.fcgi

Paste the following…

#!/usr/bin/env python2.6
import bottle
from flup.server.fcgi import WSGIServer
 
@bottle.route('/')
def index():
    return '<b>It works!</b>'
 
@bottle.route('/hello/')
def hello(name='World'):
    return bottle.template('<b>Hello {{name}}</b>!', name=name)
 
WSGIServer(bottle.default_app()).run()

To save it, simply press Ctrl + X, Y then Enter.

Time to make it executable…

chmod +x index.fcgi

Now lets clean up that download folder we made at the start…

rm -r ~/tmpdownload

That’s it! You can test the basic app included in the FastCGI file by visiting:

www.yourdomain.com/hello/john

Note: Remember to replace yourdomain.com with your actual domain.

Please Note: In some situations, you may not notice changes made to your code/website. This can be resolved by killing/stopping the index.fcgi process over SSH. For more information on how to do this, please click here.

Still have a question? Or need help?
If you need technical support with your account, please email us or chat live with a representative.

5 Comments

  • this works for me! thank you very much!

  • Will this also work if I have installed bottle using pip install? I tried and and not joy.
    What I found weird was the test instructions say to test via:
    http://www.yourdomain.com/hello/john

    (Of course using my domain)
    I don’t see how this can possibly test anything if these folders weren’t previosly created. Is something missing from this article?

    • Hi Bruce,

      I don’t see why it would not work, but there should be no reason to follow these steps if you already have bottle installed.

      Regarding the path, it will need to exist, but the code itself looks to be generating that. If you are having some troubles with your installation, I would recommend opening a support ticket from within BackStage, for more detailed information on this.

  • Do we need, bottle, flask and jango, or just one or the toher, much of the docs from bottle and flask seem very similar.

    • Hi Bruce,

      You don’t need all three, no. It is really up to you how you use these, but you can just stick to one, if you want.

Money Back Guarantees