Importing a user module into your live WSGI application

authored by Frank Lynam at 08/02/2013 18:33:06

Here’s a quick tip if you want to use multiple modules in your Python WSGI application. Say for example, you write a module called and you import this into your file, which contains the WSGI application function (your app’s entry point). If you run this code within an IDE like Eclipse, it will work fine; you will be able to call functions defined in from However, if you try to run the same code in a live Apache2 server you’ll notice that you get a HTTP Error 500, which is never nice to see.

The cause of the problem is that the WSGI module does not know where to look for the file. You can sort this out by entering the following code at the top of your module:

import os, sys
import library

The WSGI module will now know where to look for the file.