So, this should be fairly straightforward, but for the life of me I cannot figure it out. I have a Python script and I would like to run it in Alteryx. So I am using the command tool, telling it to run cmd.exe, I am attaching my script in the command arguments box and in the read results box I have added the file to which it should write.
Yet when I go and run it, it opens up the command line box but nothing happens, it seems that it is not picking up the argument and running it.
Any idea on what I am doing wrong?
Thank you!!!
Solved! Go to Solution.
Hi damiana,
were you able to run the same in the command line (not by Alteryx)
or can you post your module , wanted to see your workflow to check you are passing arguments correctly :-)
--Saravanan
The Run Command Tool options are a bit strangely worded so I will just walk through it in case this is your issue:
Write source will take whatever data is coming IN to the tool, that is the data stream that is attached to the input of the Run Command, and write it to the file or connection specified.
The point of this is to dump the data that is currently in Alteryx to a file so that your script can then read the file.
Under 'Run External Program Command:' 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 argument, you will type the location of your Python script your_python_script.py (Alteryx's default working directory is the directory of the running module so if is easiest to keep your script nearby and simply type "your_python_script.py" instead of the full path) and any - or -- options necessary. Remember to quote this string.
The default working directory for Alteryx is the directory of the running module unlesss set otherwise.
Your Python script should then write to a fileat the end of it's processing.
The Read Results should point to the file written by your Python script. This way, Alteryx can read back in the data that was procesed by the external command.
Clear as mud?
I actually just published a blog that, while not specifically on this topic, does show a couple of different examples of using the Run Command Tool to run an Rscript. This will be very similar to your setup.
https://www.interworks.com/blog/mtreadwell/2016/01/12/speed-your-analysis-alteryx-using-r-and-sqlite
Michael thank you very much, especially for taking the time to write the instructions in an **bleep**-proof way :)
It would seem that it is processing the script now, but it runs with error. It just says "The external program Python.exe returned an error code:2"
Any idea on why that might happen?
Otherwise no issues, the help you provided was already brilliant on its own!
That is the error that you see when the python script itself has an error
The best way to troubleshoot these kind of issues is to open your command prompt and run the script from there. Remember to change directories so that you are running from the same working directory as Alteryx, which is by default where the module is saved.
So from the command prompt:
cd 'directory_of_yxmd'
'path_to_python.exe path_to_script.py --options'
When you run the script this way you should see the full output of the issue causing the error.
Once you have addressed these errors, try running it again in Alteryx.
Awesome! I'm all set now! Thank you for your help!!
What I needed, just when I needed it. Thank you!
Hi Michael, Alteryx is giving me an error that the Read Results file does not exist. The Read Results is what the external command will generate and send back to Alteryx, right? Which menas that in most cases this file will not exist prior to the execution of the command. I appreciate your help
Yes, often times the file in Read Results will not exist prior to the first run. This means that Alteryx will complain about not being able to find the file. Try running the module anyway and Alteryx should realize what is going on.
Othewise, you could create a dummy file so that Alteryx has something to look at.
Hello, I am attempting to run python in Alteryx and wanted to find out what version of Python you used or would recommend?
User | Count |
---|---|
19 | |
15 | |
13 | |
9 | |
8 |