0
votes

I'm following a simple tutorial on Setting up mod_wsgi on WampServer all runs fine until I try to Import, I tried searching the net, but didn't get a working solution, is this a bug issues (maybe not) or certainly a configuration issue?

How to Import a module in mod_wsgi?

setup: windows8 64 / wampserver x64 bit / mod_wsgi x64bit

Directory:

  1. Wampserver: c:/wamp
  2. wsgi app : c:/wamp/www/wsgi
  3. Python27 : c:/python27

Alias for wsgi app: {created as per in the tutorial via wamp's create an alias option}

WSGIScriptAlias /wsgi/ "c:/wamp/www/wsgi/wsgi.py"
<Directory "c:/wamp/www/wsgi/">
    Options Indexes FollowSymLinks MultiViews
    AllowOverride all
        Order allow,deny
    Allow from all
</Directory>

wsgi.py

from paste import httpserver

try :
    p = sys.argv[1]
    command = "from %(project)s import *" % {"project": p}
    exec(command)
    httpserver.serve(app, host='127.0.0.1', port='8080')

except :
    print "Usage: python runner.py <main_package>"
    sys.exit(0)

apache-error-log:

  • Target WSGI script 'C:/wamp/www/wsgi/wsgi.py' cannot be loaded as Python module.
  • Exception occurred processing WSGI script 'C:/wamp/www/wsgi/wsgi.py'.
  • from paste import httpserver ImportError: cannot import name httpserver

However if I change the above code to:

def application(environ, start_response):
    status = '200 OK'
    output = 'Hello World!'
    response_headers = [('Content-type', 'text/plain'), ('Content-Length', str(len(output)))]
    start_response(status, response_headers)
    return [output]

It prints output.

options tried wsgi.py:

import os, sys
sys.path.append("c:\\wamp\\www\\wsgi\\paste\\")
sys.path.append(os.path.dirname(__file__))
sys.path.append('c:/wamp/www/wsgi/')
sys.path.insert(0, 'c:/wamp/www/wsgi')
sys.path.insert(1, 'c:/wamp/www')
sys.path.insert(0, "c:/wamp/www/wsgi/wsgi.py")
sys.path.insert(0, "c:/wamp/www/wsgi/paste")

Edit: paste module is in apps root directory.

2
Why aren't you installing Paste into the Python installation or using a Python virtual environment. Incorporating third party packages into your project is generally not a good idea.Graham Dumpleton
Hi @GrahamDumpleton Yeah I do agree with you that including 3rd parties in the project folder in not a good idea. I do have Paste in Python's site-pakages directory, if that's what you meant & I did include it in my apps directory as the app throws an Import error; but that didn't help either, & I don't want to use virtualenv; as I'm learning to check How I can get it to work without virtualenv.Simon K Bhatta4ya

2 Answers

0
votes

You dont mention that you have activated Python as a valid CGI in Apache.

Does this help -> Configure Apache to use Python

0
votes

Try to delete the final slash:

  WSGIScriptAlias /wsgi "c:/wamp/www/wsgi/wsgi.py"

instead of:

  WSGIScriptAlias /wsgi/ "c:/wamp/www/wsgi/wsgi.py"