python - Cannot import module -
python - Cannot import module -
i have created python web app directory structure:
# cd /usr/local/www/myapp modules layout __init__.py layout.py packages public myapp.wsgi
i have set pythonpath to:
/usr/local/www/myapp/modules:/usr/local/www/myapp/packages
in myapp.wsgi seek do:
import layout
but getting internal server error. why?
this myapp.wsgi (if remove import layout line, works):
import sys import wsgiref import layout def application(environ, start_response): response_status = '200 ok' response_body = 'hello! ' response_headers = [] content_type = ('content-type', 'text-plain') content_length = ('content-length', str(len(response_body))) response_headers.append(content_type) response_headers.append(content_length) start_response(response_status, response_headers) homecoming [response_body]
full error message getting:
internal server error server encountered internal error or misconfiguration , unable finish request. please contact server administrator, webmaster@example.com , inform them of time error occurred, , might have done may have caused error. more info error may available in server error log.
my virtualhost configuration:
<virtualhost *:80> servername localhost serveralias localhost serveradmin webmaster@example.com documentroot /usr/local/www/myapp/public <directory /usr/local/www/myapp/public> order allow,deny allow </directory> wsgiscriptalias / /usr/local/www/myapp/myapp.wsgi <directory /usr/local/www/myapp> order allow,deny allow </directory> </virtualhost>
error /var/log/httpd-error.log:
[fri jan 20 15:31:03 2012] [error] [client 192.168.201.123] mod_wsgi (pid=1725): target wsgi script '/usr/local/www/myapp/myapp.wsgi' cannot loaded python module. [fri jan 20 15:31:03 2012] [error] [client 192.168.201.123] mod_wsgi (pid=1725): exception occurred processing wsgi script '/usr/local/www/myapp/myapp.wsgi'. [fri jan 20 15:31:03 2012] [error] [client 192.168.201.123] traceback (most recent phone call last): [fri jan 20 15:31:03 2012] [error] [client 192.168.201.123] file "/usr/local/www/myapp/myapp.wsgi", line 3, in <module> [fri jan 20 15:31:03 2012] [error] [client 192.168.201.123] import layout [fri jan 20 15:31:03 2012] [error] [client 192.168.201.123] importerror: no module named layout
output of print sys.path:
first try:
python /usr/local/www/myapp/myapp.wsgi
does load correctly?
if yes, have environment (in ~/.bashrc
or such) needed app. try::
# wipe-out env env -i bash # seek 1 time again python /usr/local/www/myapp/myapp.wsgi
verify utilize same python in shell 1 used apache wsgi.
if myapp.wsgi
need env load correctly, can 1 of:
to set in in wsgi code, here illustration code.
import os, sys extra_dir = os.path.realpath(os.path.join(os.path.dirname(__file__), '..', '..')) if extra_dir not in sys.path: sys.path.append(extra_dir)
put in in origin of myapp.wsgi file.
python apache wsgi
Comments
Post a Comment