# How to invoke a Python script in UiPath using Invoke Code activity?

**URL:** <https://forum.uipath.com/t/how-to-invoke-a-python-script-in-uipath-using-invoke-code-activity/2856425>\
**Category:** Studio\
**Tags:** powershell, activities-panel, invoke-powershell, question, studio, python, system, activities\
**Created:** [June 15, 2025, 8:05pm UTC](https://forum.uipath.com/t/how-to-invoke-a-python-script-in-uipath-using-invoke-code-activity/2856425 "2025-06-15T20:05:02Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![voranir](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/voranir/32/291299_2.png) [@voranir](https://forum.uipath.com/u/voranir)\
**Post date:** [June 15, 2025, 8:05pm UTC](https://forum.uipath.com/t/how-to-invoke-a-python-script-in-uipath-using-invoke-code-activity/2856425/1 "2025-06-15T20:05:03Z")

</div>

Hello,

I want to invoke a Python script with input parameters (string, int etc).

How do I invoke using Invoke Powershell activity in UiPath?

I’m using the latest version of Python and don’t want to use Invoke Python scope.

Thanks in advance for your help!

---

<div class="post-metadata">

**Author:** ![sonaliaggarwal47](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/sonaliaggarwal47/32/234327_2.png) [@sonaliaggarwal47](https://forum.uipath.com/u/sonaliaggarwal47)\
**Post date:** [June 15, 2025, 8:31pm UTC](https://forum.uipath.com/t/how-to-invoke-a-python-script-in-uipath-using-invoke-code-activity/2856425/2 "2025-06-15T20:31:47Z")

</div>

Hi @voranir

Is there a specific reason why you don’t want to use direct python activities for this purpose?

If you only want to do it via powershell, please try code like below in command text of invoke powershell activity and see if this works

python “path\to\your\script.py” arg1 arg2

Regards  
Sonali

---

<div class="post-metadata">

**Author:** ![khissal\_ahmed1](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/khissal_ahmed1/32/466821_2.png) [@khissal\_ahmed1](https://forum.uipath.com/u/khissal_ahmed1)\
**Post date:** [June 15, 2025, 9:07pm UTC](https://forum.uipath.com/t/how-to-invoke-a-python-script-in-uipath-using-invoke-code-activity/2856425/3 "2025-06-15T21:07:49Z")

</div>

Hello,  
you can use directly an Invoke power shell activity and type “python ./pythonscript.py” input1 input2

Or  
you can use an use application activity as shown in the screenshot, and pass the command in a type into activity

 ![The image shows a user interface of a software workflow with sections for configuring a PowerShell application path, entering command-line text, and displaying an "Image Not Available" placeholder. (Légende par l'IA)](https://global.discourse-cdn.com/uipath/original/4X/d/e/d/ded1a116d660d71159b95057cd35a28150956582.png)

---

<div class="post-metadata">

**Author:** ![Aleem\_Khan](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/aleem_khan/32/534869_2.png) [@Aleem\_Khan](https://forum.uipath.com/u/Aleem_Khan)\
**Post date:** [June 16, 2025, 8:15am UTC](https://forum.uipath.com/t/how-to-invoke-a-python-script-in-uipath-using-invoke-code-activity/2856425/4 "2025-06-16T08:15:56Z")

</div>

1. Use the “Invoke PowerShell” Activity:  
Property value below:

CommandText “python  
‘C:\Path\To\YourScript.py’”  
IsScript False (Because this is a single command)  
Output Optional (if you want to capture Python’s output)  
3. Example:

CommandText = “python ‘C:\Users\YourName\Documents\my\_script.py’”  
IsScript = False

Hope this help

---

<div class="post-metadata">

**Author:** ![voranir](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/voranir/32/291299_2.png) [@voranir](https://forum.uipath.com/u/voranir)\
**Post date:** [June 16, 2025, 8:11pm UTC](https://forum.uipath.com/t/how-to-invoke-a-python-script-in-uipath-using-invoke-code-activity/2856425/5 "2025-06-16T20:11:41Z")

</div>

Hi @sonaliaggarwal47

Thank you for the reply.

The reason we are not using python activities is because the latest Python version is not compatible intgrating with UiPath.

---

<div class="post-metadata">

**Author:** ![marian.platonov](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/marian.platonov/32/260263_2.png) [@marian.platonov](https://forum.uipath.com/u/marian.platonov)\
**Post date:** [June 16, 2025, 8:20pm UTC](https://forum.uipath.com/t/how-to-invoke-a-python-script-in-uipath-using-invoke-code-activity/2856425/6 "2025-06-16T20:20:45Z")

</div>

Try this approach with Invoke Code for C#:

[UiPath.Studio.24.10.14](https://download.uipath.com/versions/24.10.14/UiPathStudio.msi)  
UiPath.System.Activities.24.10.7

Install

> **[Download .NET 8.0 Desktop Runtime (v8.0.12) - Windows x64 Installer](https://dotnet.microsoft.com/en-us/download/dotnet/thank-you/runtime-desktop-8.0.12-windows-x64-installer)**

Import these namespaces:

System  
System.Diagnostics

Invoke Code activity for Language C#:

```auto
        // Path to the Python executable
        //string pythonPath = @"C:\Program Files\Python312\python.exe";
        
        // Path to the Python script
        //string scriptPath = @"C:\Users\admin_1\Documents\PythonScriptToExecute.py";
        
         // Create a new process to run the Python script
        ProcessStartInfo start = new ProcessStartInfo();
        start.FileName = pythonPath;
        start.Arguments = scriptPath;
        start.UseShellExecute = false;
        start.RedirectStandardOutput = true;
        start.RedirectStandardError = true;
        start.CreateNoWindow = true;

        // Start the process
        using (Process process = Process.Start(start))
        {
            // Read the output from the Python script
            using (System.IO.StreamReader reader = process.StandardOutput)
            {
                result = reader.ReadToEnd();
                //Console.WriteLine("Output: " + result); // Print the result to verify
            }

            // Read any error messages from the Python script
            using (System.IO.StreamReader reader = process.StandardError)
            {
                string error = reader.ReadToEnd();
                if (!string.IsNullOrEmpty(error))
                {
                    Console.WriteLine("Error: " + error);
                }
            }
        }

```

Invoked code arguments

result → out → System.String → out\_PythonScript  
pythonPath → in → System.String → `"C:\Program Files\Python312\python.exe"`  
scriptPath → in → System.String → `"C:\Users\your_username\Documents\PythonScriptToExecute.py`"

 ![The image is a screenshot of the UiPath Studio interface, displaying a workflow that includes an activity to run a Python script, with an Invoke Code activity and a popup window showing invoked code arguments. (Captioned by AI)](https://global.discourse-cdn.com/uipath/original/4X/d/b/0/db0cc9c1d9f21f77cf467a0ac90a7e4e26fdb698.png)

PythonScriptToExecute.py content

```auto
def add_numbers(a, b):
    return a + b

# Example usage
out_results = add_numbers(5, 3)
print(out_results)

```

_Results:_

 ![image](https://global.discourse-cdn.com/uipath/original/4X/5/0/3/5038a0d4ce228ff799c87a46158b96f942966187.png)

---

<div class="post-metadata">

**Author:** ![voranir](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/voranir/32/291299_2.png) [@voranir](https://forum.uipath.com/u/voranir)\
**Post date:** [June 16, 2025, 8:46pm UTC](https://forum.uipath.com/t/how-to-invoke-a-python-script-in-uipath-using-invoke-code-activity/2856425/7 "2025-06-16T20:46:13Z")

</div>

Hi @marian.platonov,

Thank you for sharing this.

I have a script which needs input parameters.

param1 = input (“Enter Name”)  
print (“Hello” + param1)

How do I pass the argument in the code?

Thanks

---

<div class="post-metadata">

**Author:** ![marian.platonov](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/marian.platonov/32/260263_2.png) [@marian.platonov](https://forum.uipath.com/u/marian.platonov)\
**Post date:** [June 16, 2025, 9:19pm UTC](https://forum.uipath.com/t/how-to-invoke-a-python-script-in-uipath-using-invoke-code-activity/2856425/8 "2025-06-16T21:19:07Z")

</div>

Python code:

```auto
import sys

# Check if an argument was provided
if len(sys.argv) > 1:
    param1 = sys.argv[1] # Get the first command-line argument
else:
    param1 = input("Enter Name: ") # Fallback to user input if no argument is provided

print("Hello " + param1)

```

UiPath.Studio  
UiPath.System.Activities.24.10.7

Add an Input Dialog activity with output System.String **out\_Name**

 ![The image shows a UiPath workflow design featuring an input dialog box titled "Python input argument test," where the user is prompted to "Provide Name," with properties displayed on the right side. (Captioned by AI)](https://global.discourse-cdn.com/uipath/original/4X/f/1/c/f1c47c518ca4db43dd5ade0d89bc80172c3e1ff9.png)

Invoke Code activity for C#

```auto
    // Path to the Python executable
        //string pythonPath = @"C:\Program Files\Python312\python.exe";
        
        // Path to the Python script
        //string scriptPath = @"C:\Users\admin_1\Documents\PythonScriptToExecute.py";
        
         // Create a new process to run the Python script
        ProcessStartInfo start = new ProcessStartInfo();
        start.FileName = pythonPath;
        start.Arguments = scriptPath;
        start.UseShellExecute = false;
        start.RedirectStandardOutput = true;
        start.RedirectStandardError = true;
        start.CreateNoWindow = true;

        // Start the process
        using (Process process = Process.Start(start))
        {
            // Read the output from the Python script
            using (System.IO.StreamReader reader = process.StandardOutput)
            {
                result = reader.ReadToEnd();
                //Console.WriteLine("Output: " + result); // Print the result to verify
            }

            // Read any error messages from the Python script
            using (System.IO.StreamReader reader = process.StandardError)
            {
                string error = reader.ReadToEnd();
                if (!string.IsNullOrEmpty(error))
                {
                    Console.WriteLine("Error: " + error);
                }
            }
        }

```

Invoked code arguments:

result → out → System.String → out\_PythonScript  
pythonPath → in → System.String → “C:\Program Files\Python313\python.exe”  
scriptPath → in → System.String → `string.Format("""C:\Marian\Python Projects\test\sample_script_with_input.py"" {0}", out_Name)`

 ![The image shows a screenshot of a code argument configuration window with fields for name, direction, type, and value, involving a Python script setup. (Captioned by AI)](https://global.discourse-cdn.com/uipath/original/4X/4/b/8/4b8e659b62b68dda4659ecf7b0bf48ce125a9bd3.png)

_Results of execution:_

 ![image](https://global.discourse-cdn.com/uipath/original/4X/7/4/d/74d817080c466dc9ad8416c7217048e759452504.png)  
 ![This image shows a software log interface with a "Log Message" dialog box and an output console displaying the message "Hello Marian" during a sample Python execution. (Captioned by AI)](https://global.discourse-cdn.com/uipath/original/4X/4/a/a/4aa7058f3dfde37a8c7ea55e9485178f48ea3206.png)

---

<div class="post-metadata">

**Author:** ![voranir](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/voranir/32/291299_2.png) [@voranir](https://forum.uipath.com/u/voranir)\
**Post date:** [June 18, 2025, 2:36pm UTC](https://forum.uipath.com/t/how-to-invoke-a-python-script-in-uipath-using-invoke-code-activity/2856425/9 "2025-06-18T14:36:27Z")

</div>

Hi @marian.platonov,

Thank you for sharing the details.

I’m getting the below error

 ![image](https://global.discourse-cdn.com/uipath/original/4X/f/6/3/f63a993c6147bc6af9d95a359ee677ad366f1f42.png)

I’m using UiPath.System.Activities - 24.10.6

---

<div class="post-metadata">

**Author:** ![marian.platonov](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/marian.platonov/32/260263_2.png) [@marian.platonov](https://forum.uipath.com/u/marian.platonov)\
**Post date:** [June 18, 2025, 2:54pm UTC](https://forum.uipath.com/t/how-to-invoke-a-python-script-in-uipath-using-invoke-code-activity/2856425/10 "2025-06-18T14:54:49Z")

</div>

Share the project and the python code.  
Did you follow the same steps as above, or do you skipped something?

---

<div class="post-metadata">

**Author:** ![voranir](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/voranir/32/291299_2.png) [@voranir](https://forum.uipath.com/u/voranir)\
**Post date:** [June 19, 2025, 8:57pm UTC](https://forum.uipath.com/t/how-to-invoke-a-python-script-in-uipath-using-invoke-code-activity/2856425/11 "2025-06-19T20:57:45Z")

</div>

Hi @marian.platonov,

It’s working now.

I was not passing the command line arguments in the python script.

Thank you for the solution.

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/system/32/182466_2.png) [@system](https://forum.uipath.com/u/system)\
**Post date:** [June 22, 2025, 8:58pm UTC](https://forum.uipath.com/t/how-to-invoke-a-python-script-in-uipath-using-invoke-code-activity/2856425/12 "2025-06-22T20:58:39Z")

</div>

Closed on June 22, 2025, 8:58pm UTC

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.
