Enable Python on IIS (Windows)
Configure IIS to interpret Python (.py) files via the CGI handler, so web requests to your Python scripts are executed server-side.
Prerequisites
- Windows 10 or Windows Server with IIS installed
- Python 2.7 or 3.x installed (64-bit recommended for 64-bit OS)
- CGI feature enabled in IIS
Step 1 – Install Python
Download the 64-bit Python installer from python.org and install to C:\Python27\ (or your preferred path). Note the path to python.exe — you will need it in Step 4.
Step 2 – Enable IIS and CGI
- Open Windows Features (search "Turn Windows features on or off").
- Under Internet Information Services, enable:
- Web Management Tools → IIS Management Console
- World Wide Web Services → Application Development Features → CGI
- Click OK and wait for installation to complete.
Step 3 – Create a Website in IIS
- Open IIS Manager (search for "IIS" in the Start menu; run as Administrator).
- Right-click Sites → Add Website.
- Fill in the site name, physical path (your Python project folder, e.g.
C:\PythonProject), and port. - Right-click the new site → Edit Permissions → Security tab → Edit:
- Add
IUSRwith Full Control. - Add
IIS_IUSRSwith Full Control.
- Add
Step 4 – Map Python as a CGI Script Handler
- Select your site in IIS Manager.
- Double-click Handler Mappings.
- In the Actions pane, click Add Script Map.
- Fill in the dialog:
Request path : *.py Executable : C:\Python27\python.exe %s %s Name : Python Interpreter - Click OK and confirm the dialog to allow the handler.
Step 5 – Configure the Application Pool
- Right-click your site → Manage Website → Advanced Settings.
- Set Application Pool to
DefaultAppPool. - Optionally enable Directory Browsing so you can browse and click .py files directly.
Step 6 – Verify
Create a minimal test script in your project folder:
print('Content-Type: text/plain')
print('')
print('Hello, world!')
Right-click the site → Manage Website → Browse. Your browser opens the file listing. Click MyPythonApp.py — you should see Hello, world! in the browser.
Troubleshooting
- 500 Internal Server Error: Confirm the executable path in the script map is correct and includes
%s %s. - 403 Forbidden: Check that IUSR and IIS_IUSRS have Full Control on the project folder.
- CGI not listed in Handler Mappings: Re-enable the CGI Windows Feature and restart IIS.