Community Spring Cleaning week is here! Join your fellow Maveryx in digging through your old posts and marking comments on them as solved. Learn more here!

Alteryx Designer Desktop Knowledge Base

Definitive answers from Designer Desktop experts.

How To: Run a Python Script in Alteryx

MattD
Alteryx Alumni (Retired)
Created

If you are using a version of Designer2018.3, use the Python tool! If you are on an older version, this article is for you.

Below is an example demonstrating the use of the Run Command tool to execute a Python script in the Designer and use its output in the workflow:

1.png

For a Python script, your Command should be Python.exe. If the directory where Python exists is in your system path variable, you can simply type Python.exe. Otherwise you will have to give it the full path, keeping in mind to quote the string if there are spaces (e.g. "Program Files"). In Command Arguments, you will type the location of your Python script (Alteryx's default working directory is the directory of the running module so it may be easiest to keep your script in the same folder to simply type "your_python_script.py" rather than the full path) and any - or -- options necessary. Remember to quote this string!

The example script from the attached simply sends text to a text file to be used as input for the Designer (note: it will not run unless you have configured your python environment😞

2.png 3.png

As you can see, we’ve successfully executed a python script and used the Read Results input to bring the result of the script into the Designer for further processing.

Attachments
Comments
jyeh
7 - Meteor

Thanks for the post.

 

I found the following to work for me to return some status codes to Alteryx workflow.

 

The first argument would pass the data to the python program

The second arugment would return the status code back to Alteryx

 

Using the %temp% ensures the process can run in parallel with other processes.

 

Run Command

mayscw10
7 - Meteor
Very helpful to get started - just as a precaution - are there any material differences in 11.0.6 and/or 11.x?
jyeh
7 - Meteor
Actually, I use the cmd.exe as the program and arguments as

/C python.exe python_program.py ....

HTH
Jordi
pbrink
8 - Asteroid

I downloaded the example and everything worked as described about but when I run my own scripts I receive "Error: Run Command (3): The external program "C:\Python27\python.exe" returned an error code: 2"

 

Any ideas?

jyeh
7 - Meteor

@pbrink - What happen when you try to run the command from the terminal/cmd.exe? What error message do you get?

 

C:\Python27\python.exe python_program.py?

 

Although, with 18.3, you may want to check if the python tool can help in your situation https://help.alteryx.com/current/Python.htm

pvara
8 - Asteroid

Thank you for the example, I have downloaded the workflow and it works perfectly. I do have a follow up question regarding the text.txt file. Why is that needed? I would like to run other py scripts how can I do that without having the text.txt file.

 

Thank you,

Pete

sarangp
5 - Atom
Can the run external program command and the command arguments be taken from Text input tool?
kenlo
5 - Atom

I am trying to call a python script that takes in no arguments, but when I add a run command it's asking for an input and output connection?  I thought the input / output source are optional?

GreggD
8 - Asteroid

I have the same situation and question.

How can I execute my Python script which has not inputs or outputs?

jyeh
7 - Meteor
Try the following:

No Output

Commnad: cmd.exe

Command Arguments /C C:\path_to_python\python.exe python.py >> %Engine.TempFilePath%log.txt

Input: %Engine.TempFilePath%log.txt

Add a Browser tool after the Run Command if needed to check the contents of the log.txt file.

I hope this helps.