Results 1 to 3 of 3

Thread: Can I run Pylons? (Python framework)

  1. #1
    Join Date
    Jun 2006
    Posts
    1

    Question Can I run Pylons? (Python framework)

    Hi all,

    I read bluehost supports Ruby on Rails, so I figured it should be possible to run Pylons, a Rails like framework for Python. Both can be deployed using fastcgi.

    Can anyone tell me if this is possible, or give me hints on possible drawbacks or problems?

    Thanks!

  2. #2
    Join Date
    Jul 2007
    Posts
    1

    Default

    I too would like to know if this is possible. Getting the design set up and ready to impliment. Seems like BlueHost supports python, so it may be possible to install pylons?

  3. #3
    Join Date
    Apr 2007
    Posts
    1

    Default How to use pylons

    This is kind of an old post, but I'll go ahead and respond here in case any one else is interested in doing this too.

    These are the steps I took to get pylons up and running. Currently I have it set up as a cgi script with no redirection. Eventually I am hoping to have fastcgi and redirection working as well.

    Here is what you will need to do in summary:
    1. install python >= 2.4
    2. create a pylons development environment
    3. create a pylons project
    4. create a cgi script to run your project


    This may seem like a lot, but it is fairly automated and worked fairly well on the server that hosts my domain.

    The rest of these instructions assume that you have connected to your account using ssh. There should be other instructions in this forum describing how to do that.


    = Install Python =

    Pylons requires python >= 2.4. The default version of python at the time of this post is 2.3. The host that I am on also has python2.6, but I couldn't get that to work. I installed python2.6 because that is the current version at the time of this post.

    Find some version that you like here http://www.python.org/download/. I like do download and build in a subdirectory named "dist". The following steps show how to build and install your own version of python. The key is "--prefix=$HOME" parameter passed to configure. After installing it you need to use that installation of python. For the remainder of these instructions, I'll use $HOME/bin/<program> to highlight the fact that I am using a specific program, but at some point it makes sense to change the PATH variable to have $HOME/bin as the first entry.

    Code:
    [~/dist]# wget http://www.python.org/ftp/python/2.6.2/Python-2.6.2.tar.bz2
    ...
    [~/dist]# tar -jxvf Python-2.6.2.tar.bz2 
    [~/dist]# cd Python-2.6.2
    [~/dist/Python-2.6.2]# 
    [~/dist/Python-2.6.2]# ./configure --prefix=$HOME
    ...
    [~/dist/Python-2.6.2]# make
    ...
    [~/dist/Python-2.6.2]# make install
    [~/dist/Python-2.6.2]# $HOME/bin/python
    Python 2.6.2 (r262:71600, Jul  4 2009, 16:47:33) 
    [GCC 3.4.6 20060404 (Red Hat 3.4.6-10)] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>>
    = Create a Pylons Virtual Environment =

    These instructions are from the Pylons "Getting Started" section of their documentation.

    http://pylonshq.com/docs/en/0.9.7/gettingstarted/

    The Pylons installation instructions show how to create a virtual development environment. To make use of the virtual environment, you will need to source a file to change your environment. After that point it is not necessary to use the full path to commands.

    I am going to put them in a subdirectory called pylons, but this is just a personal preference.

    Code:
    [~/pylons]# $HOME/bin/python2.6 go-pylons.py env
    [~/pylons]# source env/bin/activate
    (env)[~/pylons]#
    From now on, there is no need to use the full path to python or and related tools because activate has created a virtual environment.

    Now create a project.

    Code:
    (env)[~/pylons]# paster create -t pylons helloworld
    The paster command will ask some questions, just hit enter for the defaults for now. It will create a directory called helloworld.

    Paster can serve the application, but this doesn't work for my account. I believe that requires a dedicated IP address. This is how to get the configuration working with CGI.

    Deploy the app in development mode. This is needed so that python can find the helloworld package. There are other installation methods, this is suitable for quick turnaround when developing an application.

    Code:
    (env)[~/pylons/helloworld]# $HOME/bin/python2.6 setup.py develop
    ...
    Create a wrapper cgi script. I created it in the same directory as helloworld. Then copied to ~/public_html/cgi-bin. The original filename is $HOME/pylons/helloworld/helloworld.py. Replace the absolute paths with the correct ones for your home directory. Note that the python path is the one in the virtual environment.

    Code:
    #!/home/vexiterc/pylons/env/bin/python2.6
    
    import sys
    from paste.deploy import loadapp
    import wsgiref.handlers
    
    sys.path = ['/home/vexiterc/pylons/helloworld'] + sys.path
    
    wsgi_app = loadapp('config:/home/vexiterc/pylons/helloworld/development.ini')
    wsgiref.handlers.CGIHandler().run(wsgi_app)
    Make it readable and executable, then copy the file to ~/public_html/cgi-bin/. You should be able to run it from there. It will generate an error becuase it is not running in a web context, but the script should not die because of import errors. Also I would prefer to use a symlink. I was not able to get that to work on bluehost, so the file ends up being in two places. I always edit the original then copy it to cgi-bin.

    Code:
    [~/pylons/helloworld]# chmod a+rx helloworld.py
    [~/pylons/helloworld]# cp helloworld.py ~/public_html/cgi-bin
    [~/pylons/helloworld]# cd ~/public_html/cgi-bin
    [~/public_html/cgi-bin]# ./helloworld.py
    Traceback (most recent call last):
      File "/home/vexiterc/lib/python2.6/wsgiref/handlers.py", line 93, in run
        self.result = application(self.environ, self.start_response)
      File "/home/vexiterc/pylons/env/lib/python2.6/site-packages/Paste-1.7.2-py2.6.egg/paste/cascade.py", line 117, in __call__
        v = app(environ_copy, repl_start_response)
      File "/home/vexiterc/pylons/env/lib/python2.6/site-packages/Paste-1.7.2-py2.6.egg/paste/urlparser.py", line 451, in __call__
        return self.add_slash(environ, start_response)
      File "/home/vexiterc/pylons/env/lib/python2.6/site-packages/Paste-1.7.2-py2.6.egg/paste/urlparser.py", line 497, in add_slash
        url = request.construct_url(environ, with_query_string=False)
      File "/home/vexiterc/pylons/env/lib/python2.6/site-packages/Paste-1.7.2-py2.6.egg/paste/request.py", line 219, in construct_url
        url += environ['SERVER_NAME']
    KeyError: 'SERVER_NAME'
    Status: 500 Dude, this is whack!
    Content-Type: text/plain
    Content-Length: 59
    
    A server error occurred.  Please contact the administrator.
    The previous error is ok, but these are not.

    Python cannot find your module.

    Code:
    (env)[~/public_html/cgi-bin]#/helloworld.py
    Traceback (most recent call last):
      File "./helloworld.py", line 9, in <module>
        wsgi_app = loadapp('config:/home/vexiterc/pylons/helloworld/development.ini')
      File "/home/vexiterc/pylons/env/lib/python2.6/site-packages/PasteDeploy-1.3.3-py2.6.egg/paste/deploy/loadwsgi.py", line 204, in loadapp
    
    ...
    
      File "/home/vexiterc/pylons/env/lib/python2.6/site-packages/setuptools-0.6c9-py2.6.egg/pkg_resources.py", line 524, in resolve
    pkg_resources.DistributionNotFound: helloworld
    This is fixed by
    Code:
    (env)[~/pylons/helloworld]# python setup.py develop
    python cannot find config.middleware, also part of your package.

    Code:
    (env)[~/public_html/cgi-bin]# ./helloworld.py 
    Traceback (most recent call last):
      File "./helloworld.py", line 9, in <module>
        wsgi_app = loadapp('config:/home/vexiterc/pylons/helloworld/development.ini')
    ...
    find_egg_entry_point
        possible.append((entry.load(), protocol, entry.name))
      File "/home/vexiterc/pylons/env/lib/python2.6/site-packages/setuptools-0.6c9-py2.6.egg/pkg_resources.py", line 1913, in load
    ImportError: No module named config.middleware
    This is fixed by adding the path to your project in the cgi script
    Code:
    sys.path = ['/home/vexiterc/pylons/helloworld'] + sys.path
    Now try it from the web and it should work.

    http://www.vexiter.com/cgi-bin/helloworld.py

    Since the pylons project was installed in develop mode, changes made in the project directory should appear without having to reinstall, but I haven't tested that yet.

    Some future things I am trying to figure out are how to use fastcgi, how to do a real install, and how to avoid adding the path information "sys.path" to the cgi script. There should be some way around that anyway as that will cause problems for a real deployment.

    Hopefully this will help some other people that are interested in using pylons on bluehost.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •