Would you like to learn how to install IIS and enable the Python CGI feature on a computer running Windows? In this tutorial, we are going to show you how to enable the Python CGI feature on the IIS server.

• Windows 2012 R2
• Windows 2016
• Windows 2019
• Python 3
• IIS

Tutorial Windows - IIS Installation

Open the Server Manager application.

Access the Manage menu and click on Add roles and features.

Windows 2012 add role

On the Server Roles screen, select the option named: Web Server IIS.

Click on the Next button.

IIS Installation

On the following screen, click on the Add features button.

IIS Features

On the Features screen, click on the Next button.

Windows 2012 - Features

On the Role service screen, click on the Next button.

IIS - Role Service

On the Summary screen, click on the Install button.

IIS installation summary

Congratulations! You have finished the IIS service installation on a computer running Windows.

Tutorial IIS - Enabling the CGI feature

Open the Server Manager application.

Access the Manage menu and click on Add roles and features.

Windows 2012 add role

On the Server Roles screen, expand the entry named: Web Server IIS.

Access the Application development menu and select the option named: CGI

Click on the Next button.

IIS enable CGI

On the Features screen, click on the Next button.

Windows 2012 - Features

On the Summary screen, click on the Install button.

IIS CGI Installation

Congratulations! You have finished the CGI feature installation on IIS.

Tutorial Windows - Python Installation

Access the Python website and download the latest version of the Python installer.

In our example, we downloaded the file named: Python-3.8.4-amd64.exe

Python Installer Windows

As the administrator, start the Python installation.

Python Installation Windows

Select both checkboxes on the bottom of the screen.

Click on the button to customize the Python installation.

Python install Windows

Select all checkboxes and click on the Next button.

Windows Python Installation

Select the checkbox named: Install for all users.

Change the Python installation path to the Root of drive C.

Click on the Next button.

Install Python Windows

Wait for the Python installation to finish.

Python Installation Path

In our example, Python was installed on the following directory.

Copy to Clipboard

Reboot the computer.

Congratulations! You have finished the Python installation on Windows.

Tutorial IIS - Enable Python on the IIS server

Start the application named: IIS Manager.

Start IIS Windows

On the IIS Manager application, select your IIS server name.

On the right part of the screen, access the option named: Handler Mappings

IIS Handler mapping

Select the option named: Add Script Map

IIS - Add script map

Perform the following configuration:

• Request Path - *.py
• Executable - C:\Python\Python38\python.exe %s %s
• Interpreter - Python Interpreter

Click on the OK button.

IIS Python

If the following message is presented, click on the Yes button.

IIS CGI Restriction

Restart the IIS service.

Congratulations! You successfully enabled Python on the IIS server.

Tutorial IIS - Creating a Python page

Start a new DOS command-line prompt.

Windows DOS Prompt

Use the PIP application to install a Python library named ART.

Copy to Clipboard

In our example, we are going to use this library to create a test page.

Access the IIS root directory.

Copy to Clipboard

Create a Python test page.

Copy to Clipboard

Use the Notepad application to open the Python test page.

Replace its content with the following code.

Copy to Clipboard

Open your browser and enter the IP address of your web server plus /test.py.

In our example, the following URL was entered in the Browser:

• http://172.31.7.220/test.py

The Python page should display the following message.

IIS - Python web page

Congratulations! The Python extension was installed successfully on IIS.