Installing Pylons on Virtualenv

Posted Thursday, 04 March 2010 at 03:29 by Andrew Liu
Tagged: python | linux | web development
Read more blogs...


Installing Pylons can be a bit of a swim upstream if you don't really know what you are doing.  Things have been made a lot more simple by using the setuptools package, if you can get your head around it (more like, get your head around its simplicity).


So how to we get Pylons up and running?  Firstly, follow this tutorial on setting up a virtual environment.  More often than not this is a good idea, otherwise your installation files will go into the main Python site-packages directory, and it will become an ugly mess.  Using a virtual environment helps you work in segregated environments, that are independent to each other.  That way, you could use different sets of libraries and tools, and not have them bloat your standard python installation (thus making life difficult for other users).


I'll assume that you have a virtual environment running under "myapp".  Activate the virtual environment for starters.



> cd myapp

> . activate



Now we use the setuptools package to grab pylons over the internet.  Setuptools comes with a binary called "easy_install" that makes this seamless.



(myapp)> easy_install "Pylons==0.9.7"

Searching for Pylons==0.9.7
Best match: Pylons 0.9.7

Finished processing dependencies for Pylons==0.9.7




This installs the Pylons files into your virtual environment.  We will also want to use SQLAlchemy as well.  You may choose not to, but that is your preference.  SQLAlchemy provides a database layer to access a number of databases seamlessly.



(myapp)> easy_install sqlalchemy

Searching for sqlalchem
Best match: SQLAlchemy 0.5.2

Finished processing dependencies for sqlalchemy



Now what we want to do is create a pylons application from this.  We will name this new application "myapp".  This name is the python name that we will be using to import.  Typically, I 

have it the same as "myapp" because I'd have one virtual environment called "myapp" that holds only one pylons application called "myapp".  I 

think having multiple pylons applications within a single virtual environment defeats the whole purpose of virtual environments, but hey, I 

may change my mind in the future.




(myapp)> paster create --template=pylons myapp
Selected and implied templates:
  Pylons#pylons  Pylons application template

  egg:      myapp
  package:  myapp
  project:  myapp
Enter template_engine (mako/genshi/jinja2/etc: Template language) ['mako']:
Enter sqlalchemy (True/False: Include SQLAlchemy 0.5 configuration) [False]: True
Creating template pylons
Creating directory ./myapp


(myapp)> ls

activate  bin  myapp  include  lib


This creates directory called "myapp".  Just to let you know the directory structure again, it is:


> /

  > home

    > aliu

      > myapp      [ The virtual environment ]

        > bin     

        > myapp    [ The pylons application ]

        > include

        > lib


The first thing we want to do is decide what port this pylons application will run on.  The standard port is 5000, but if you have lots of pylons applications running (and if you are serious, you should have 2 or 3 installations just for the one application for DEV, TEST and PRODUCTION), you will need to change this port number.  I will change mine to 5100.  Edit the "development.ini file" and change the line in red below.




(myapp)> vi myapp/development.ini


 13 [server:main]
 14 use = egg:Paste#http
 15 host =
 16 port = 5100

(myapp)> ls

activate  bin  myapp  include  lib


However, Pylons wont run unless a database is installed, and the default database SQLAlchemy uses is pysqlite.  This is where things get a bit ugly for Pylons.  For now, lets remove the requirement for a database, and attend to that later after we get Pylons running. Comment out the line below in the "development.ini" file.



(myapp)> vi myapp/development.ini


 33 # SQLAlchemy database URL
 34 #sqlalchemy.url = sqlite:///%(here)s/development.db




And then remove the database engine initialisation.



(myapp)> vi myapp/myapp/config/


 40     # Setup the SQLAlchemy database engine
 41     #engine = engine_from_config(config, 'sqlalchemy.')
 42     #init_model(engine)




Now we can start our server.  I like to have a shortcut to this, as you'll be doing it quite often in development.  So I'll call my startup script "".  Don't forget to chmod the new file so that we can execute it.


(myapp)> vi


  1 #!/bin/sh
  3 cd myapp
  4 paster serve --reload development.ini

(myapp)> chmod 755

(myapp)> ls

activate  bin  myapp  include  lib


And start the server.



(myapp)> sh
Starting subprocess with file monitor
Starting server in PID 13735.
serving on


If your browser cannot see anything, you may need to turn off iptables.

> chkconfig --list iptables
iptables        0:off   1:off   2:on    3:on    4:on    5:on    6:off


> chkconfig iptables off

> chkconfig --list iptables
iptables        0:off   1:off   2:off   3:off   4:off   5:off   6:off


While we're here, might as well do the same to ip6tables too.

> chkconfig --list ip6tables
ip6tables        0:off   1:off   2:on    3:on    4:on    5:on    6:off


> chkconfig ip6tables off

> chkconfig --list ip6tables
ip6tables        0:off   1:off   2:off   3:off   4:off   5:off   6:off


If you are running off a network computer, you will have to change the "development.ini" file and specify the host to listen on (more often than not, that is the IP address of the computer pylons is running on).


Go to your browser, and voila!


Web News

Company Blog

Search Behaviour

Posted Tuesday, 19 October 2010 at 05:58 by Andrew Liu

As an SEO provider, you have one main goal. Get your clients website to show up in search results fo...


sm bus drivers missing in Device Manager

Posted Sunday, 18 April 2010
Updated Sunday, 24 February 2013 at 06:39 by Andrew Liu

When installing a new Windows XPinstallation, I seemingly always miss some drivers. One that trouble...


Multiple Domains for SEO performance?

Posted Friday, 05 March 2010 at 23:13 by Andrew Liu

Online businesses and websites that cover a broad range of topics or one large topic are sometimes b...


Tag Clouds - SEO or not?

Posted Thursday, 04 March 2010 at 04:34 by Andrew Liu

A tag cloud or word cloud is a visual depiction of tags or words related to a site, typically used t...


Mozilla Thunderbird and Gmail IMAP Attachments Bug

Posted Wednesday, 03 March 2010 at 20:15 by Andrew Liu

I've been using Gmail since its early inception, and Iwas one of the first to utilise Gmail's IMAPfe...


Read more blogs...