# Using 3rd-party java python libraries

**URL:** <https://forum.inductiveautomation.com/t/using-3rd-party-java-python-libraries/44738>\
**Category:** Maker\
**Created:** [March 22, 2021, 5:52am UTC](https://forum.inductiveautomation.com/t/using-3rd-party-java-python-libraries/44738 "2021-03-22T05:52:13Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![e0310912](https://avatars.discourse-cdn.com/v4/letter/e/6de8d8/32.png) [@e0310912](https://forum.inductiveautomation.com/u/e0310912)\
**Post date:** [March 22, 2021, 5:52am UTC](https://forum.inductiveautomation.com/t/using-3rd-party-java-python-libraries/44738/1 "2021-03-22T05:52:13Z")

</div>

Hi all, I would like to ask how do I add and use 3rd-party java python libraries in Ignition in the scripting window.

I would like to use [Datamelt](https://datamelt.org/?id=current) because of the array feature it has similar to Numpy using [jnumeric](https://handwiki.org/wiki/DMelt:Numeric/8_Numeric_Python)

Code in Python but in C so I need to convert it into something Jython can recognize:

```auto
import numpy #array and math functions
import time #for time delay, depends on how fast we want to refresh the image

### intialising variables for the data processing algorithm, need to add this to SCADA code.
history = numpy.full((32, 32,5), numpy.nan)
idx = 0
movavgmax = numpy.full((5,1), numpy.nan)
movavgmin = numpy.full((5,1), numpy.nan)
hyst = 0.8;
             
    ###start of data processing algorith
    ### compute moving average from last 5 images
    array = rawdata
    idx = idx + 1
    history[:,:,(idx-1)%5] = array
    movavgarray = numpy.nanmean(history,axis=2)

```

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [March 22, 2021, 12:39pm UTC](https://forum.inductiveautomation.com/t/using-3rd-party-java-python-libraries/44738/2 "2021-03-22T12:39:37Z")

</div>

The simplest deployment is to stick the jars in your Ignition gateway’s `../lib/core/common` and restart. Then those jars will be available for import like any other java library in jython (no wildcards).

A more professional and reliable method would be to deploy the jars in a `.modl` file with simple module hooks to register scripting functions.

---

<div class="post-metadata">

**Author:** ![e0310912](https://avatars.discourse-cdn.com/v4/letter/e/6de8d8/32.png) [@e0310912](https://forum.inductiveautomation.com/u/e0310912)\
**Post date:** [March 22, 2021, 1:37pm UTC](https://forum.inductiveautomation.com/t/using-3rd-party-java-python-libraries/44738/3 "2021-03-22T13:37:38Z")

</div>

> [@pturmel](#):
>
> The simplest deployment is to stick the jars in your Ignition gateway’s `../lib/core/common` and restart. Then those jars will be available for import like any other java library in jython (no wildcards).

So the first way is like putting the library into a file location that Ignition can find and it will be as simple as this for the importing like importing libraries in python ?  
[Running this Example on a Scripting Console in ignition](https://handwiki.org/wiki/DMelt:Numeric/8_Numeric_Python) after putting the jar file into the gateway's directory

```auto
import jnumeric.JNumeric as np
a = np.array(10)
b = np.array( [[1,0],[0,1]],'f') # assume float
print b

```

> [@pturmel](#):
>
> A more professional and reliable method would be to deploy the jars in a `.modl` file with simple module hooks to register scripting functions.

The second way would be like this:

[How to use Maven](http://maven.apache.org/guides/getting-started/maven-in-five-minutes.html) & [Using Maven-plugin with Ignition SDK to make a .modl file](https://docs.inductiveautomation.com/display/SE/The+Ignition+Maven+Plugin)

I'm a bit short of time for my project... so I might go with the first way for now in this case. But is there any issues using the first way that I should be aware of ?

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [March 22, 2021, 1:47pm UTC](https://forum.inductiveautomation.com/t/using-3rd-party-java-python-libraries/44738/4 "2021-03-22T13:47:09Z")

</div>

Your imports will have to use DMelt’s java class names, not the python names. But otherwise, yes, it’s that simple.

---

<div class="post-metadata">

**Author:** ![e0310912](https://avatars.discourse-cdn.com/v4/letter/e/6de8d8/32.png) [@e0310912](https://forum.inductiveautomation.com/u/e0310912)\
**Post date:** [March 22, 2021, 2:03pm UTC](https://forum.inductiveautomation.com/t/using-3rd-party-java-python-libraries/44738/5 "2021-03-22T14:03:02Z")

</div>

Something like this example ? [Java Class importing in Jython](https://www.jython.org/jython-old-sites/archive/21/docs/usejava.html)

I never used or learn java , so it’s a bit new to me.

---

<div class="post-metadata">

**Author:** ![e0310912](https://avatars.discourse-cdn.com/v4/letter/e/6de8d8/32.png) [@e0310912](https://forum.inductiveautomation.com/u/e0310912)\
**Post date:** [March 22, 2021, 4:06pm UTC](https://forum.inductiveautomation.com/t/using-3rd-party-java-python-libraries/44738/6 "2021-03-22T16:06:07Z")

</div>

> [@pturmel](#):
>
> The simplest deployment is to stick the jars in your Ignition gateway’s `../lib/core/common` and restart. Then those jars will be available for import like any other java library in jython (no wildcards).

I tried inserting the jar file into the directory as shown in the picture below:

 ![Placing Jar file](https://us1.discourse-cdn.com/inductiveautomation/original/3X/2/d/2d060ad5f10ad376a75421feee6c6c61ae9d5540.jpeg)

Then using the Script Console to run it, receives an error that the module is not found :

 ![Script_Console](https://us1.discourse-cdn.com/inductiveautomation/original/3X/4/3/438cf2431878d0571aeea8e0207a43724b874bc8.jpeg)

[Link to download dmelt-2.7 file](https://datamelt.org/download/dmelt-2.7.zip)

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [March 22, 2021, 4:09pm UTC](https://forum.inductiveautomation.com/t/using-3rd-party-java-python-libraries/44738/7 "2021-03-22T16:09:12Z")

</div>

Did you restart your gateway and then restart your designer?

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [March 22, 2021, 4:16pm UTC](https://forum.inductiveautomation.com/t/using-3rd-party-java-python-libraries/44738/8 "2021-03-22T16:16:37Z")

</div>

I doubt jnumeric’s java package name is “jnumeric”. Open the jar and look at the heirarchy of folders. According to github, it should be “com.github.tbekolay.jnumeric”.

---

<div class="post-metadata">

**Author:** ![e0310912](https://avatars.discourse-cdn.com/v4/letter/e/6de8d8/32.png) [@e0310912](https://forum.inductiveautomation.com/u/e0310912)\
**Post date:** [March 22, 2021, 4:32pm UTC](https://forum.inductiveautomation.com/t/using-3rd-party-java-python-libraries/44738/9 "2021-03-22T16:32:51Z")

</div>

I did and even restarted my computer

---

<div class="post-metadata">

**Author:** ![e0310912](https://avatars.discourse-cdn.com/v4/letter/e/6de8d8/32.png) [@e0310912](https://forum.inductiveautomation.com/u/e0310912)\
**Post date:** [March 22, 2021, 4:35pm UTC](https://forum.inductiveautomation.com/t/using-3rd-party-java-python-libraries/44738/10 "2021-03-22T16:35:50Z")

</div>

![From jnumeric.jar](https://us1.discourse-cdn.com/inductiveautomation/original/3X/e/2/e211851b9608b2f5cacd56948ce6995f6b9853c2.jpeg)

 ![From dmelt folder original](https://us1.discourse-cdn.com/inductiveautomation/original/3X/5/b/5b427ee700d8e6bd8e57ba65fde8c5c6b4c02e6e.jpeg)  
Using 7-Zip to open the .jar file

---

<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:** [March 22, 2021, 4:37pm UTC](https://forum.inductiveautomation.com/t/using-3rd-party-java-python-libraries/44738/11 "2021-03-22T16:37:33Z")

</div>

If you want to use `JNumeric` you’ll also need to install the Python lib:  
[https://sourceforge.net/projects/jnumerical/files/latest/download](https://sourceforge.net/projects/jnumerical/files/latest/download)  
This would go into `/user-lib/pylib/` in the installation directory.

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [March 22, 2021, 4:41pm UTC](https://forum.inductiveautomation.com/t/using-3rd-party-java-python-libraries/44738/12 "2021-03-22T16:41:47Z")

</div>

The sourceforge repo has a discussion from 2009 where somebody reports it doesn't work with Jython 2.2...

> We just updated to Jython 2.2, and found that JNumeric is incompatible. It appears most (if not all) the issues are in the PyMultiarray, and are related to signature changce in the jython.jar file. Help....?

This is one of the most dead and abandoned looking projects I've ever seen. I doubt this will work.

---

<div class="post-metadata">

**Author:** ![e0310912](https://avatars.discourse-cdn.com/v4/letter/e/6de8d8/32.png) [@e0310912](https://forum.inductiveautomation.com/u/e0310912)\
**Post date:** [March 23, 2021, 3:33am UTC](https://forum.inductiveautomation.com/t/using-3rd-party-java-python-libraries/44738/13 "2021-03-23T03:33:50Z")

</div>

Thank you, I manage to run the [example](https://handwiki.org/wiki/DMelt:Numeric/8_Numeric_Python) from Dmelt using [GitHub - tbekolay/jnumeric: NumPy-like syntax for Jython](https://github.com/tbekolay/jnumeric) JNumeric File

I placed the files in both the Ignition gateway’s `../lib/core/common` and the `/user-lib/pylib/` mentioned by PGriffith and the Script Console recognizes the functions

 ![WorkingForNow](https://us1.discourse-cdn.com/inductiveautomation/original/3X/0/6/0625b2ef0834e93c58c9ba79a41c5ab8e63e987d.jpeg)

---

<div class="post-metadata">

**Author:** ![PRAMANJ](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pramanj/32/66935_2.png) [@PRAMANJ](https://forum.inductiveautomation.com/u/PRAMANJ)\
**Post date:** [March 23, 2021, 5:34am UTC](https://forum.inductiveautomation.com/t/using-3rd-party-java-python-libraries/44738/14 "2021-03-23T05:34:41Z")

</div>

just restarting the Ignition gateway and the designer (if required in clients) is enough.
