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

(myapp)>

 

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
Reading http://pypi.python.org/simple/Pylons/
Reading http://www.pylonshq.com/
Reading http://pylons.groovie.org/
Best match: Pylons 0.9.7
...

Finished processing dependencies for Pylons==0.9.7
(myapp)>

 

 

 

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
Reading http://pypi.python.org/simple/sqlalchemy/
Reading http://www.sqlalchemy.org
Best match: SQLAlchemy 0.5.2
...

Finished processing dependencies for sqlalchemy
(myapp)>

 

 

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

Variables:
  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 = 127.0.0.1
 16 port = 5100
 17
...

(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

...

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

...


 

 

And then remove the database engine initialisation.

 

 

(myapp)> vi myapp/myapp/config/environment.py

...

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

 43
...


 

 

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 "start.sh".  Don't forget to chmod the new file so that we can execute it.

 

(myapp)> vi start.sh

...

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

(myapp)> chmod 755 start.sh

(myapp)> ls

activate  bin  myapp  include  lib  start.sh

 

And start the server.

 

 

(myapp)> sh start.sh
Starting subprocess with file monitor
Starting server in PID 13735.
serving on http://127.0.0.1:5100

 

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

The Dangers of HTML5: WebSockets and Stable Standards
New HTML5 technologies like WebSockets offer some amazing new opportunities for Web developers. But they also show how implementing unstable standards may cause more harm to a site than the benefits of the technology. What is the role of browsers and how should developers plan for when developing with HTML5?
2011-05-09T21:00:23-04:00

Internet Explorer 6: What Have We Learned?
IE6 shipped more than 10 years ago, but its non-standard implementation of the shifting standards of 2001 still haunts today's developers. As the Web shifts to HTML5, and new versions of IE, Firefox and Chrome debut, have we learned the lessons of IE6?
2011-05-09T20:50:33-04:00

Crank Up the Volume with HTML5 Music
With HTML5, music is making a comeback on the Web. Create amazing music site experiences where adding an audio file is as simple as inserting an image and users have more pause and play music outside a browser. The introduction of the tag eliminates the need for external music players, allowing for true integration of sound in your website.
2011-05-09T20:44:42-04:00

Dojo.behavior: Write Modularized HTML Document Event Handling
The dojo.behavior module provides a simple and lightweight mechanism for listening to HTML document events. Find out what makes dojo.behavior one of the best event handling mechanisms around.
2011-04-27T14:11:59-04:00

The Dojo Publish/Subscribe Event Mechanism
Learn how to use the Dojo Toolkit's versatile ContentPane widget to load dynamic content into your Web pages.
2011-04-25T07:04

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 client’s website to show up in search res...

Read more...



"sm bus" drivers missing in Device Manager

Posted Thursday, 18 March 2010 at 20:51 by Andrew Liu


When installing a new Windows XP installation, I seemingly always miss some drivers. One that troub...

Read more...



Link Building SEO Strategies

Posted Monday, 08 March 2010
Updated Tuesday, 09 March 2010 at 02:09 by Andrew Liu


Link building might be a necessary step for your search engine optimisation campaign, but very few p...

Read more...



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...

Read more...



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...

Read more...



Read more blogs...