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 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 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 ... (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] (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
|
And then remove the database engine initialisation.
(myapp)> vi myapp/myapp/config/environment.py ... 39
|
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 (myapp)> chmod 755 start.sh (myapp)> ls activate bin myapp include lib start.sh |
And start the server.
(myapp)> sh start.sh |
If your browser cannot see anything, you may need to turn off iptables.
> chkconfig --list iptables
> chkconfig iptables off > chkconfig --list iptables |
While we're here, might as well do the same to ip6tables too.
> chkconfig --list ip6tables
> chkconfig ip6tables off > chkconfig --list ip6tables |
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!
Posted Tuesday, 19 October 2010 at 05:58 by Andrew Liu
Posted Sunday, 18 April 2010
Updated Sunday, 24 February 2013 at 06:39 by Andrew Liu
Posted Friday, 05 March 2010 at 23:13 by Andrew Liu
Posted Thursday, 04 March 2010 at 04:34 by Andrew Liu
Posted Wednesday, 03 March 2010 at 20:15 by Andrew Liu