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

Rent the Runway CEO: Gender discrimination is larger workplace issue than sexual harassment
Jennifer Hyman runs a fast growing startup and helps women become successful in their businesses through Project Entrepreneur accelerator programs
--- 21 Oct 2017 10:26 AM

Vision is the next big challenge for chips
Neural engines are already showing up in phones and chipmakers are racing to develop more powerful hardware to meet demand for vision processing in a growing list of applications.
--- 21 Oct 2017 05:45 AM

Get a $1,000 software and services bundle for $49
Packed with tools designed for business growth, Briefcase offers tremendous value. There's just one catch.
--- 21 Oct 2017 04:56 AM

Elephone S8 hands-on: A solid, no-nonsense phone for business use
The Elephone S8 is a tri-bezel-less phone with a huge screen and a gorgeous glass back that is great for consumers and business users.
--- 21 Oct 2017 04:34 AM

Google expands tech startup acceleration projects in LatAm
The company is turning its So Paulo venue into a hub to foster ventures across the region.
--- 21 Oct 2017 03:40 AM

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

Read more...



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

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



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



Read more blogs...