Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7085225
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T07:23:54+00:00 2026-05-28T07:23:54+00:00

I have created a python web app with this directory structure: # cd /usr/local/www/myapp

  • 0

I have created a python web app with this directory structure:

# cd /usr/local/www/myapp

modules
    layout
        __init__.py
        layout.py
packages
public
myapp.wsgi

I have set my PYTHONPATH to:

/usr/local/www/myapp/modules:/usr/local/www/myapp/packages

In myapp.wsgi I try to do:

import layout

But I am getting Internal server error. Why?

This is my myapp.wsgi (if I remove the import layout line, it 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)
        return [response_body]

Full error message I am getting:

Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator, webmaster@example.com and inform them of the time the error occurred, and anything you might have done that may have caused the error.

More information about this error may be available in the 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 from all
    </Directory>

    WSGIScriptAlias / /usr/local/www/myapp/myapp.wsgi

    <Directory /usr/local/www/myapp>
    Order allow,deny
    Allow from all
    </Directory>

</VirtualHost>

Error from /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 be loaded as 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 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:

enter image description here

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T07:23:55+00:00Added an answer on May 28, 2026 at 7:23 am

    First try:

    python /usr/local/www/myapp/myapp.wsgi
    

    Does it load correctly?

    If yes, then probably you have some environment (in ~/.bashrc or such) which is needed for your app. Try::

    # to wipe-out extra env
    env -i bash
    # try again
    python /usr/local/www/myapp/myapp.wsgi
    

    Verify you use same python in your shell as the one used by apache WSGI.

    If your myapp.wsgi need any extra env to load correctly, then you can do one of:

    • set python path in apache, or
    • set in runtime in your myapp.wsgi

    To set in in your WSGI code, here is the example 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 the beginning of your myapp.wsgi file.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a simple python web site using Google App Engine. Currently, the
I've created a Python web app using CherryPy, and have deployed in on my
I've created a web app in Python 3. It all runs beautifully until I
I have created a web application hosted on Google App Engine (Java). Now my
I have created a Python module that creates and populates several SQLite tables. Now,
I have created a Python file to generate a Mandelbrot set image. The original
I have created some python code which creates an object in a loop, and
we are trying to create a calendar function in python. we have created a
I have a berkeley db file (*.bdb) which is created by the C implementation(python
I have a python script the runs this code: strpath = sudo svnadmin create

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.