Forums

How do you do something like start a pyramid project and run it in production?

I have a site that i've put together using Pyramid. I'd now like to put it on the web using this website. How do I go about doing this using this website? Note that i'd like to run it the appropriate way with workers rather than just running my py file containing

# serve app
app = config.make_wsgi_app()
server = make_server('0.0.0.0', 8080, app)
server.serve_forever()

More specifically, if someone could explain how to take the "tasks" tutorial and turn it into a hosted project here, that would be greatly appreciative.

In your wsgi.py file (you'll find a button to edit it by clicking the "Existing apps and other WSGI framworks" button):

import os
import sys
path = '/home/<user>/projects/my_pyramid_project'
if path not in sys.path:
    sys.path.append(path)
application = config.make_wsgi_app()

Thanks, that's helpful but doesn't solve my problem i'm afraid :(

Once I do that I get

[Tue Apr 24 15:22:43 2012] Traceback (most recent call last):
[Tue Apr 24 15:22:43 2012]   File "/bin/serve_wsgi.py", line 53, in main
[Tue Apr 24 15:22:43 2012]     application = get_application_with_error_logger(error_log)
[Tue Apr 24 15:22:43 2012]   File "/bin/serve_wsgi.py", line 46, in get_application_with_error_logger
[Tue Apr 24 15:22:43 2012]     wsgi_module = imp.load_source('wsgi', '/var/www/wsgi.py')
[Tue Apr 24 15:22:43 2012]   File "/var/www/wsgi.py", line 84, in <module>
[Tue Apr 24 15:22:43 2012]     application = config.make_wsgi_app()
[Tue Apr 24 15:22:43 2012] NameError: name 'config' is not defined

So I tried importing config after the line defining my path and I get this:

[Tue Apr 24 15:23:46 2012] Traceback (most recent call last):
[Tue Apr 24 15:23:46 2012]   File "/bin/serve_wsgi.py", line 53, in main
[Tue Apr 24 15:23:46 2012]     application = get_application_with_error_logger(error_log)
[Tue Apr 24 15:23:46 2012]   File "/bin/serve_wsgi.py", line 46, in get_application_with_error_logger
[Tue Apr 24 15:23:46 2012]     wsgi_module = imp.load_source('wsgi', '/var/www/wsgi.py')
[Tue Apr 24 15:23:46 2012]   File "/var/www/wsgi.py", line 82, in <module>
[Tue Apr 24 15:23:46 2012]     from tasks import config
[Tue Apr 24 15:23:46 2012] ImportError: No module named tasks

Ah. It looks like the tasks tutorial is supposed to all be in the same file. You should do the tutorial all in the wsgi.py file with only one difference: All the code in the

if __name__ == '__main__':

should not be wrapped in the if and the last few lines should be:

# serve app
application = config.make_wsgi_app()

instead of

# serve app
app = config.make_wsgi_app()
server = make_server('0.0.0.0', 8080, app)
server.serve_forever()

I've reworked my code into being callable..

I'm still having trouble importing tasks however.

import os
import sys
import tasks

path = '/home/MorePyPlease/tasks'
if path not in sys.path:
    sys.path.append(path)
application = tasks.make_app()

I still get this

[Tue Apr 24 19:22:26 2012] Traceback (most recent call last):
[Tue Apr 24 19:22:26 2012]   File "/bin/serve_wsgi.py", line 53, in main
[Tue Apr 24 19:22:26 2012]     application = get_application_with_error_logger(error_log)
[Tue Apr 24 19:22:26 2012]   File "/bin/serve_wsgi.py", line 46, in get_application_with_error_logger
[Tue Apr 24 19:22:26 2012]     wsgi_module = imp.load_source('wsgi', '/var/www/wsgi.py')
[Tue Apr 24 19:22:26 2012]   File "/var/www/wsgi.py", line 81, in <module>
[Tue Apr 24 19:22:26 2012]     import tasks
[Tue Apr 24 19:22:26 2012] ImportError: No module named tasks

Fixed my own problem.

The import needed to be after the path append.

That's good to hear, glad it's working!

I have used the following in wsgi.py to deploy a regular Pyramid project.

import os
import sys
from pyramid.paster import get_app

path = '/home/barnsey/env/lib/python2.6/site-packages'
if path not in sys.path:
    sys.path.append(path)

application = get_app('/home/barnsey/env/mystuff/production.ini', 'main')

It seems to work ok, but if anyone could suggest a better way, i'd be greatful.

This was super helpful to me. Thanks Barnsey!

That was really helpful. this should be documented on this site. Thanks Barnsey.

We could definitely add that to the help pages. Would anything beyond the WSGI file sample that @barnsey provided be necessary?