简体   繁体   中英

Import modules with mod_wsgi

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.

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

Does this help -> Configure Apache to use Python

Try to delete the final slash:

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

instead of:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM