title: Cannot import module
body: <p>I have created a python web app with this directory structure:</p>
  
  <pre><code># cd /usr/local/www/myapp
  
  modules
      layout
          __init__.py
          layout.py
  packages
  public
  myapp.wsgi
  </code></pre>
  
  <p>I have set my PYTHONPATH to:</p>
  
  <pre><code>/usr/local/www/myapp/modules:/usr/local/www/myapp/packages
  </code></pre>
  
  <p>In myapp.wsgi I try to do:</p>
  
  <pre><code>import layout
  </code></pre>
  
  <p>But I am getting Internal server error. Why?</p>
  
  <p>This is my myapp.wsgi (if I remove the import layout line, it works):</p>
  
  <pre><code>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]
  </code></pre>
  
  <p>Full error message I am getting:</p>
  
  <pre><code>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.
  </code></pre>
  
  <p>My virtualhost configuration:</p>
  
  <pre><code>&lt;VirtualHost *:80&gt;
  
      ServerName localhost
      ServerAlias localhost
      ServerAdmin webmaster@example.com
  
      DocumentRoot /usr/local/www/myapp/public
  
      &lt;Directory /usr/local/www/myapp/public&gt;
      Order allow,deny
      Allow from all
      &lt;/Directory&gt;
  
      WSGIScriptAlias / /usr/local/www/myapp/myapp.wsgi
  
      &lt;Directory /usr/local/www/myapp&gt;
      Order allow,deny
      Allow from all
      &lt;/Directory&gt;
  
  &lt;/VirtualHost&gt;
  </code></pre>
  
  <p>Error from /var/log/httpd-error.log:</p>
  
  <pre><code>[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 &lt;module&gt;
  [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
  </code></pre>
  
  <p>Output of print sys.path:</p>
  
  <p><img src="https://i.stack.imgur.com/041Cg.png" alt="enter image description here"></p>