Python Run Script Tasks Failing on Windows Computers
search cancel

Python Run Script Tasks Failing on Windows Computers

book

Article ID: 225064

calendar_today

Updated On: 04-25-2025

Products

Client Management Suite IT Management Suite

Issue/Introduction

When targeting a Windows computer where Python is installed with a Run Script task and the Script type is set to Python Script, the task fails with a return code of 2.

The script task succeeds if targeting a Linux computer with Python installed. 

Environment

ITMS 8.6 RU1

Cause

A Patch variable incorrectly set during the installation of Python and/or the installation was set to the default and the path is inside the User area.

Resolution

Locate the path to Python.exe. In testing, this was set to Program Files instead of the default, and the Python.exe was found in C:\Program Files\Python\Python39.

At a command prompt, run:

set PATH=%PATH%;C:\Program Files\Python\Python39

Python Run Script tasks then ran successfully.

In another instance, the user installed Python using the default path, which would be C:\Users\<USERNAME>\AppData\Local\Programs\Python\Python39

Because of this, the Script Task would fail with exit code 2. Setting the Script Task > Advanced option to run as the logged on user allowed the script task to run successfully.