Alteryx Designer Desktop Discussions

Find answers, ask questions, and share expertise about Alteryx Designer Desktop and Intelligence Suite.

Schedule/RunPython Script using alteryx

swapsingh2712
8 - Asteroid

Hello All,

 

I created a python script in vscode and want to run/schedule this python script using alteryx.

 

I got this post from the community

 

https://community.alteryx.com/t5/Alteryx-Designer-Discussions/Run-a-python-script-in-Alteryx/td-p/10... 

 

As per the above post,I've tried running the script using "run command" tool but it's giving me the error as "error code 2". although my script works fine when I'm running it in Vscode terminal.

 

Wanted to try "Python" tool but it my script does not have any input or output also it's not integrated in Jupyter Notebook.

 

Could you please advise.

 

BR

swapsingh

 

8 REPLIES 8
CathyS_Slalom
9 - Comet

Hi @swapsingh2712 , In order to use the python tool, you would need to read the data first and connect the python tool. Click the python tool, you will see the configuration window below, you can click the menu --> Alteryx to import script/notebook. After that read the data using df = Alteryx.read('#1'), the data you read in will be stored as pandas df. If you have multiple data want to use, you can read as df2 =  Alteryx.read('#2')

CathyS_Slalom_1-1667577151568.png

 

CathyS_Slalom_0-1667577088444.png

 

aduval
6 - Meteoroid

Hi @swapsingh2712

 

I use Alteryx to trigger python only scripts using this method.

 

https://community.alteryx.com/t5/Alteryx-Designer-Discussions/Python-Code-Tool-Script-Runner-Macro-C... 

 

It allows you to input a script to run and does not have to be a Jupyter notebook.

 

Let me know if you have any other questions when trying to get it working. I would be happy to help you troubleshoot.

 

- Adam

swapsingh2712
8 - Asteroid

@aduval Thank you so much for suggesting this macro. but for some reason, I'm getting the below error when trying to run the original macro

 

"Python (10) ---------------------------------------------------------------------------¶FileNotFoundError Traceback (most recent call last)¶<ipython-input-3-4b0cb414fd18> in <module>¶ 44 ¶ 45 code_path = os.path.join(workflow_dir, folder, script_file)¶---> 46 exec(open(code_path).read(), globals())¶FileNotFoundError: [Errno 2] No such file or directory: '\\\\Mac\\Google Drive\\Alteryx\\Python Iris Clustering\\Python Iris Clustering Analysis\\_python\\Python Iris 2.py'¶"

 

Do I have to make any changes to the code?

 

 I've already updated my path and file name and connected it to macro, but it's giving me below error

 

" Python Script Runner (1) Tool #10: ---------------------------------------------------------------------------¶NameError Traceback (most recent call last)¶<ipython-input-3-4b0cb414fd18> in <module>¶ 44 ¶ 45 code_path = os.path.join(workflow_dir, folder, script_file)¶---> 46 exec(open(code_path).read(), globals())¶<string> in <module>¶<string> in Download_Report_Files(ENV, ReportName, FolderPath)¶NameError: name '__file__' is not defined¶

 

Please advise
"

aduval
6 - Meteoroid

@swapsingh2712

 

My apologies, I forgot that I adapted that macro to only take in a python script and run it. I believe that macro actually requires a file input and a script input. Take a look at the attached workflow. The jupyter notebook should run the python script from the text input tool (need to include file path and script name). Sorry for the confusion.

swapsingh2712
8 - Asteroid

Hey @aduval 

 

looks like this workflow is running my script but for some reason, it's giving me the below error

 

"Python (14) ---------------------------------------------------------------------------¶NameError Traceback (most recent call last)¶<ipython-input-3-4b0cb414fd18> in <module>¶ 44 ¶ 45 code_path = os.path.join(workflow_dir, folder, script_file)¶---> 46 exec(open(code_path).read(), globals())¶<string> in <module>¶<string> in Download_Report_Files(ENV, ReportName, FolderPath)¶NameError: name '__file__' is not defined¶"

 

I'll give you a brief about my script.

 

So when it runs, it opens a browser, downloads the file from the location and then triggers a email with file attachments.

 

The original script is running without any issues,  the alteryx workflow failing when it hits the code where the browser opens.

 

Do you know if we can make any changes in the python tool to make it work?

 

and thank you so much for sharing the workflow, I appreciate it.

aduval
6 - Meteoroid

Are you able to try a dummy script and see if can run a simple print statement?

swapsingh2712
8 - Asteroid

@aduval : Yes I tried and it's running the print statement. It's failing whenever the script is trying to open the browser.

 

I tried modifying my script to run Google Chrome in headless mode, but due to my company network restrictions, the authentication is not going through.

 

Any suggestion how to run it in alteryx without using the headless mode?

 

 

aduval
6 - Meteoroid

Sorry. I don't have any current experience with that specific use case. 

Labels