Configuring Python with IIS 7.0

by timvasil 3/5/2012 11:06:00 PM

Recently I thought I'd give Python a try for web development.  Configuring it with 64-bit Windows and IIS 7.0 took a bit of trial and error, though, and I didn't find these steps comprehensively laid out anywhere on the web.  So here goes:

  1. Download the 32-bit version of Python 2.6 here.  To work with the Python ISAPI filter, it's important you choose the 32-bit variant of the 2.6 version.  I accepted all defaults during the installation.
  2. Download Python ISAPI Extension for IIS 2.6 (pyisapie) here.  I unzipped it into a subfolder of C:\Python2.6
  3. Create an environment variable called PYTHONHOME and set it to where you installed Python, e.g. C:\Python2.6.
  4. Restart Windows.  Since IIS inherits its environment block from services.exe, which cannot be restarted, you need to reboot so the ISAPI filter sees the PYTHONHOME variable.
  5. Configure IIS to use the ISAPI extension:
    1. Create a 32-bit application pool (Advanced Settings > Enable 32-Bit Applications = True)
    2. Create a web site (or application) and configure it to use the application pool you just created
    3. Add a "Script Map" handler mapping with a request path of "*.py", an executable location of the Python ISAPI DLL (e.g. C:\Python26\PyISAPIe-1.1.0-rc4-Py2.6\PyISAPIe.dll), and any name you'd like.  (Accepting Request Restriction defaults is fine.)
  6. In the home directory of your website, create a Python script to test your handiwork, e.g. a file named page.py with this code:
     
    from Http import *
    def Request():
        Header("Content-type: text/html")
        Write("Hello, World!")
      
  7. Visit the URL (e.g. http://website/page.py); if all is well, the message "Hello, world!" appears!

Tags:

IIS | ISAPI | Python

Search

Calendar

«  May 2013  »
SuMoTuWeThFrSa
2829301234
567891011
12131415161718
19202122232425
2627282930311
2345678

View posts in large calendar

Recent posts

Recent comments

Archive