# Running external python script from button event

**URL:** <https://forum.inductiveautomation.com/t/running-external-python-script-from-button-event/71028>\
**Category:** Ignition\
**Tags:** ignition81, perspective\
**Created:** [March 14, 2023, 2:32pm UTC](https://forum.inductiveautomation.com/t/running-external-python-script-from-button-event/71028 "2023-03-14T14:32:57Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Lukasz\_Wieckowski](https://avatars.discourse-cdn.com/v4/letter/l/ce7236/32.png) [@Lukasz\_Wieckowski](https://forum.inductiveautomation.com/u/Lukasz_Wieckowski)\
**Post date:** [March 14, 2023, 2:32pm UTC](https://forum.inductiveautomation.com/t/running-external-python-script-from-button-event/71028/1 "2023-03-14T14:32:57Z")

</div>

Hello everyone, I write python3 script, which connect to IP camera, take a screenshot and saves the photo to a folder on the disk. I want to run this external python script from button event in perspective view in Ignition. I am trying two external script calls:  
1)  
system.util.execute(['C:/Program Files/Python311/python.exe', 'C:/Praca/Testy kamer/test.py'])  
2)  
import subprocess  
pythonPath = "C:/Program Files/Python311/python.exe"  
scriptPath = "C:/Praca/Testy kamer/test.py"

result = subprocess.check\_output([pythonPath, scriptPath])

When I run these calls from the script console in ignition - the script executes correctly and the image is written to disk.

But if I run these calls from button event on click - external script does not execute.  
When I click button in preview mode I am getting such error:

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/0/0/0059dcb3b1633e0fb6759857effd4dc9751ed481.png)

Python script exist in the gateway. I set permission for folder with python script for gateway service.

How to run external python script from button event in Ignition?

---

<div class="post-metadata">

**Author:** ![Matrix\_Engineering](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/matrix_engineering/32/19781_2.png) [@Matrix\_Engineering](https://forum.inductiveautomation.com/u/Matrix_Engineering)\
**Post date:** [March 14, 2023, 2:50pm UTC](https://forum.inductiveautomation.com/t/running-external-python-script-from-button-event/71028/2 "2023-03-14T14:50:29Z")

</div>

It is against the forum policy to start multiple topics regarding the same subject.

> [@Running external python script in Ignition](https://forum.inductiveautomation.com/t/running-external-python-script-in-ignition/70769):
>
> Hello everyone. I write external python script, which connect to IP camera, take a screenshot and saves the photo to a folder on the disk. I use system.util.execute to run this script from Ignition: system.util.execute(['C:/Program Files/Python311/python.exe', 'C:/Praca/Testy kamer/test.py']) When I run this line of code from the script console in ignition - the script executes correctly and the image is written to disk. But if I run system.util.execute function from button event on click - e…

---

<div class="post-metadata">

**Author:** ![Matrix\_Engineering](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/matrix_engineering/32/19781_2.png) [@Matrix\_Engineering](https://forum.inductiveautomation.com/u/Matrix_Engineering)\
**Post date:** [March 14, 2023, 2:51pm UTC](https://forum.inductiveautomation.com/t/running-external-python-script-from-button-event/71028/3 "2023-03-14T14:51:33Z")

</div>

[https://forum.inductiveautomation.com/faq](https://forum.inductiveautomation.com/faq)

---

<div class="post-metadata">

**Author:** ![Salvatore\_Maniaci](https://avatars.discourse-cdn.com/v4/letter/s/858c86/32.png) [@Salvatore\_Maniaci](https://forum.inductiveautomation.com/u/Salvatore_Maniaci)\
**Post date:** [September 10, 2024, 2:07pm UTC](https://forum.inductiveautomation.com/t/running-external-python-script-from-button-event/71028/4 "2024-09-10T14:07:14Z")

</div>

From what I have tried on this forum, python scripts must be stored in the gateway to be ran, and in order to run those scripts, the python exe needs to be stored in the gateway as well. Because you are using python 3, you would have to install python 3 in the gateway. I still havent figured out how to do this.

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [September 10, 2024, 2:20pm UTC](https://forum.inductiveautomation.com/t/running-external-python-script-from-button-event/71028/5 "2024-09-10T14:20:11Z")

</div>

> [@Salvatore\_Maniaci](#):
>
> From what I have tried on this forum, python scripts must be stored in the gateway to be ran, and in order to run those scripts, the python exe needs to be stored in the gateway as well

This is only true for the Perspective Module or Tags. The Vision Module, which does have access to the client machine can execute code on that machine. Weather or not it should is a different question.
