# Python scripting problem

**URL:** <https://forum.inductiveautomation.com/t/python-scripting-problem/28411>\
**Category:** Ignition\
**Created:** [September 19, 2019, 8:24pm UTC](https://forum.inductiveautomation.com/t/python-scripting-problem/28411 "2019-09-19T20:24:40Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![lrhyrne](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrhyrne/32/12097_2.png) [@lrhyrne](https://forum.inductiveautomation.com/u/lrhyrne)\
**Post date:** [September 19, 2019, 8:24pm UTC](https://forum.inductiveautomation.com/t/python-scripting-problem/28411/1 "2019-09-19T20:24:40Z")

</div>

I’m using Ignition 7.9.8 and would like to use the python ‘importlib’ module and importing it in a button pressed event scripting area causes an error saying 'no module named import lib.  
I need this to import and call functions out of a script external to the ignition system.  
Basically, the following line:  
**import importlib.util**  
does not work.

Any help?

---

<div class="post-metadata">

**Author:** ![dkhayes117](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dkhayes117/32/68344_2.png) [@dkhayes117](https://forum.inductiveautomation.com/u/dkhayes117)\
**Post date:** [September 19, 2019, 8:35pm UTC](https://forum.inductiveautomation.com/t/python-scripting-problem/28411/2 "2019-09-19T20:35:56Z")

</div>

> [@How do we import new python libraries to ignition](http://forum.inductiveautomation.com/t/how-do-we-import-new-python-libraries-to-ignition/10037):
>
> Hi, I’m just curious, what if i want to import: import win32file (python library) and that python library doesn’t exist in ignition, is there a way we can add that to ignition library or something? Thanks.

Note that v7.9 jython uses python 2.5. Python libraries that belong to version 2.7 and up will not work. They also must not have any dependencies on other languages like C.

---

<div class="post-metadata">

**Author:** ![lrhyrne](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrhyrne/32/12097_2.png) [@lrhyrne](https://forum.inductiveautomation.com/u/lrhyrne)\
**Post date:** [September 20, 2019, 2:05pm UTC](https://forum.inductiveautomation.com/t/python-scripting-problem/28411/3 "2019-09-20T14:05:07Z")

</div>

These are modules that I have written myself. I just want to call them from within Ignition. The link below has the directions I followed:

[https://support.inductiveautomation.com/index.php?/Knowledgebase/Article/View/98/2/importing-and-using-3rd-party-python-libraries-in-ignition](https://support.inductiveautomation.com/index.php?/Knowledgebase/Article/View/98/2/importing-and-using-3rd-party-python-libraries-in-ignition)

After seeing the import fail (“Error: ‘No module named [module\_name]’”)

Any other things I am missing?

---

<div class="post-metadata">

**Author:** ![bfuson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bfuson/32/4597_2.png) [@bfuson](https://forum.inductiveautomation.com/u/bfuson)\
**Post date:** [September 20, 2019, 2:56pm UTC](https://forum.inductiveautomation.com/t/python-scripting-problem/28411/4 "2019-09-20T14:56:35Z")

</div>

So you imported your .py files to `C:\Program Files\Inductive Automation\Ignition\user-lib\pylib` and reloaded your script console?

Maybe try  
`from importlib import util`?

---

<div class="post-metadata">

**Author:** ![lrhyrne](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrhyrne/32/12097_2.png) [@lrhyrne](https://forum.inductiveautomation.com/u/lrhyrne)\
**Post date:** [September 20, 2019, 2:59pm UTC](https://forum.inductiveautomation.com/t/python-scripting-problem/28411/5 "2019-09-20T14:59:14Z")

</div>

How do I reset the script console?

---

<div class="post-metadata">

**Author:** ![lrhyrne](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrhyrne/32/12097_2.png) [@lrhyrne](https://forum.inductiveautomation.com/u/lrhyrne)\
**Post date:** [September 20, 2019, 3:01pm UTC](https://forum.inductiveautomation.com/t/python-scripting-problem/28411/6 "2019-09-20T15:01:09Z")

</div>

bfuson,

Yes, I placed my py file (1) in the pylib directory and also tried placing that file in yet another directory and adding the from import myclass

this yielded the same results. no module named myclass

---

<div class="post-metadata">

**Author:** ![bfuson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bfuson/32/4597_2.png) [@bfuson](https://forum.inductiveautomation.com/u/bfuson)\
**Post date:** [September 20, 2019, 3:22pm UTC](https://forum.inductiveautomation.com/t/python-scripting-problem/28411/7 "2019-09-20T15:22:33Z")

</div>

Per [Script Console - Ignition User Manual 8.0 - Ignition Documentation](https://docs.inductiveautomation.com/display/DOC80/Script+Console)  
Click the reset icon

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/2X/9/92507689da4e26412d4f87353e1a0e76d8884a64.png)

---

<div class="post-metadata">

**Author:** ![lrhyrne](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrhyrne/32/12097_2.png) [@lrhyrne](https://forum.inductiveautomation.com/u/lrhyrne)\
**Post date:** [September 20, 2019, 3:29pm UTC](https://forum.inductiveautomation.com/t/python-scripting-problem/28411/8 "2019-09-20T15:29:21Z")

</div>

OK. Still the same thing after the ‘reload’

---

<div class="post-metadata">

**Author:** ![bfuson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bfuson/32/4597_2.png) [@bfuson](https://forum.inductiveautomation.com/u/bfuson)\
**Post date:** [September 20, 2019, 3:32pm UTC](https://forum.inductiveautomation.com/t/python-scripting-problem/28411/9 "2019-09-20T15:32:29Z")

</div>

Share your module?

---

<div class="post-metadata">

**Author:** ![lrhyrne](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrhyrne/32/12097_2.png) [@lrhyrne](https://forum.inductiveautomation.com/u/lrhyrne)\
**Post date:** [September 20, 2019, 3:45pm UTC](https://forum.inductiveautomation.com/t/python-scripting-problem/28411/10 "2019-09-20T15:45:06Z")

</div>

Pretty simple, just trying to show a dialog that proves the script was run/called.

Here is the source:  
from tkinter import messagebox

class iaUtils():  
def DisplayMessage(\_message):  
messagebox.showinfo(“Information”,“iaUtils recieved:” + \_message)

---

<div class="post-metadata">

**Author:** ![bfuson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bfuson/32/4597_2.png) [@bfuson](https://forum.inductiveautomation.com/u/bfuson)\
**Post date:** [September 20, 2019, 3:53pm UTC](https://forum.inductiveautomation.com/t/python-scripting-problem/28411/11 "2019-09-20T15:53:14Z")

</div>

> [@dkhayes117](#):
>
> They also must not have any dependencies on other languages like C

tkinter is the standard python interface for tcl-tk. Tcl is a C library, which means it's effectively off-limits for usage in Ignition/Jython. There is a Java implementation of tcl, but you probably don't want to go down that road.

In Ignition you're much better off sticking with java.awt or javax.swing for display purposes. The easiest way to say, open a message box, is by using Ignition's built-in system.gui.messageBox() function.

---

<div class="post-metadata">

**Author:** ![lrhyrne](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrhyrne/32/12097_2.png) [@lrhyrne](https://forum.inductiveautomation.com/u/lrhyrne)\
**Post date:** [September 20, 2019, 3:56pm UTC](https://forum.inductiveautomation.com/t/python-scripting-problem/28411/12 "2019-09-20T15:56:39Z")

</div>

MessageBox was only trying to show the script was called. Didn’t realize how limited the extensibility of the scripting is. I will ttry to reform my script and see how it goes.

---

<div class="post-metadata">

**Author:** ![chi](https://avatars.discourse-cdn.com/v4/letter/c/0ea827/32.png) [@chi](https://forum.inductiveautomation.com/u/chi)\
**Post date:** [September 20, 2019, 3:56pm UTC](https://forum.inductiveautomation.com/t/python-scripting-problem/28411/13 "2019-09-20T15:56:49Z")

</div>

You are writing about two different modules here. importlib.util is a Python 3 system module that is not available in Ignitions Phyton 2.5.  
If your module references importlib you need to remove that reference.

---

<div class="post-metadata">

**Author:** ![bfuson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bfuson/32/4597_2.png) [@bfuson](https://forum.inductiveautomation.com/u/bfuson)\
**Post date:** [September 20, 2019, 4:22pm UTC](https://forum.inductiveautomation.com/t/python-scripting-problem/28411/14 "2019-09-20T16:22:11Z")

</div>

@chi is also correct about importlib

The knowledge base article you linked is clear about both cases:

> 1. The library or module is not written in C and is not dependent on C / C-Python features
> 2. The library is Python 2.5 compatible (\*as of Ignition 7.8, Ignition uses Jython 2.5)

Ignition's scripting facilities are top-tier as far as convenience and extensibility are concerned. The default GUI toolkit you get with Jython just happens to be swing, not tcl.tk. I believe you could, in theory, package up Jacl in an Ignition module, import it, and create tk GUIs in Jython.

Or you can code up screens using swing in Jython.  
Or you can use the Vision Designer to graphically create windows and then call them through scripting.

[https://jython.readthedocs.io/en/latest/chapter16/](https://jython.readthedocs.io/en/latest/chapter16/)

---

<div class="post-metadata">

**Author:** ![lrhyrne](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrhyrne/32/12097_2.png) [@lrhyrne](https://forum.inductiveautomation.com/u/lrhyrne)\
**Post date:** [September 20, 2019, 4:29pm UTC](https://forum.inductiveautomation.com/t/python-scripting-problem/28411/15 "2019-09-20T16:29:57Z")

</div>

Can there by any imports? For example ‘import os’?

---

<div class="post-metadata">

**Author:** ![bfuson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bfuson/32/4597_2.png) [@bfuson](https://forum.inductiveautomation.com/u/bfuson)\
**Post date:** [September 20, 2019, 4:40pm UTC](https://forum.inductiveautomation.com/t/python-scripting-problem/28411/16 "2019-09-20T16:40:17Z")

</div>

Yes, most python standard library imports work fine:

```auto
os, sys, re, functools, subprocess, __future__ , etc...

```

You can even import objects from Java:

```auto
from java.lang import reflect
from javax.swing import SwingUtilities, JComponent
from java.io import File, FileWriter

```

And from the Ignition namespace:

```auto
from com.inductiveautomation.factorypmi.application import FPMIApp, VisionDesktop

```

Just to give a few examples.

---

<div class="post-metadata">

**Author:** ![lrhyrne](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrhyrne/32/12097_2.png) [@lrhyrne](https://forum.inductiveautomation.com/u/lrhyrne)\
**Post date:** [September 20, 2019, 5:28pm UTC](https://forum.inductiveautomation.com/t/python-scripting-problem/28411/17 "2019-09-20T17:28:08Z")

</div>

Nice. Just needed the clarification. At first it seemed like you were saying I could not yse ANY imports in he script I’m calling from Ignition side.

---

<div class="post-metadata">

**Author:** ![lrhyrne](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrhyrne/32/12097_2.png) [@lrhyrne](https://forum.inductiveautomation.com/u/lrhyrne)\
**Post date:** [September 20, 2019, 5:33pm UTC](https://forum.inductiveautomation.com/t/python-scripting-problem/28411/18 "2019-09-20T17:33:55Z")

</div>

I have asked this elsewhere, but am going to ask here also, since you guys seem to be responding and knowledgeable.

IN working with an Easy Chart component, I would like to interrogate the Chart in python and retrieve a list of tags (with their paths) that the chart is using. I have some extra data I would like to value-add to the chart.

Any thoughts?

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [September 20, 2019, 5:42pm UTC](https://forum.inductiveautomation.com/t/python-scripting-problem/28411/19 "2019-09-20T17:42:07Z")

</div>

Tag pens are contained in a dataset in the chart properties. The scripting reference would be `<chartComponent>.tagPens`.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/2X/6/6db08af6de7588c6478a97ec3117be9afb86f4f1.png)

---

<div class="post-metadata">

**Author:** ![lrhyrne](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrhyrne/32/12097_2.png) [@lrhyrne](https://forum.inductiveautomation.com/u/lrhyrne)\
**Post date:** [September 20, 2019, 6:10pm UTC](https://forum.inductiveautomation.com/t/python-scripting-problem/28411/20 "2019-09-20T18:10:46Z")

</div>

Yes, i’m confused though. My Dataset Viewer is full to the gills with rows, but my event.source.parent.getComponent(“Easy Chart”).tagPens.RowCount is 0.

[Next page](https://forum.inductiveautomation.com/t/python-scripting-problem/28411.md?page=2)
