Fail to import 3rd party Module and Path Local

Hi everyone!

I need help about a integration with library python that need, i installed a server apps with ignition en centos 7 and need gevent , ari library between other , i follow the guide for add 3rd party library in path /var/lib/ignition/user-lib/pylib/site-packages my server, but no works throws this error in console the designer to import geven for example:

Traceback (most recent call last):
File “”, line 1, in
File “C:\Users\Gabriel Mata.ignition\cache\gw192.168.100.53_80\C0\pylib\site-packages\gevent_init_.py”, line 87, in
from gevent._hub_local import get_hub
File “C:\Users\Gabriel Mata.ignition\cache\gw192.168.100.53_80\C0\pylib\site-packages\gevent_hub_local.py”, line 101, in
import_c_accel(globals(), 'gevent._hub_local’)
File “C:\Users\Gabriel Mata.ignition\cache\gw192.168.100.53_80\C0\pylib\site-packages\gevent_util.py”, line 105, in import_c_accel
mod = importlib.import_module(cname)
File "C:\Users\Gabriel Mata.ignition\cache\gw192.168.100.53_80\C0\pylib\site-packages\importlib_init
.py", line 37, in import_module
import(name)
ImportError: No module named __hub_local

You can see that path throw is windows mode, i dont understand why if where try developer its a server linux, also if need execute a script .py that are in the linux system and you don’t get it on the route that I specify It shows me the local path of the PC where I am developing

you can help me please.

Two problems.

  1. gevent is trying to import a base C library, which won’t work - Ignition uses Jython, which is a Python interpreter that runs inside the Java Virtual Machine. As such, it does not have access to lower-level pre-compiled C code like “standard” Python distributions, which are technically CPython. From some quick googling, it looks like it’s possible to run gevent on PyPy (a pure-Python Python interpreter) but you may have to jump through some hoops. Also, keep in mind that Ignition <=7.9.* is using a Python 2.5 interpreter, and Ignition >=8.0.* is “only” using a Python 2.7 interpreter - any Python 3 modules will not work.

  2. The error being thrown references Windows paths because the script you’re running is running on the local machine. The ‘Script Console’ tool in the designer is compiling and running that script locally, in the local JVM that’s running the designer. Script scoping is extremely important to pay attention to in Ignition. Any scripts you write inside of a Vision client are going to run locally, and only have access to resources on that machine. We automatically synchronize the script library from the gateway to any running designers and clients, but you still need to pay a lot of attention to scoping. Scripts that execute on the gateway would include (but is not limited to!) tag event scripts, gateway tag change scripts, any Perspective scripting, scripts in reports, or scripts in alarm notification pipelines.

2 Likes

Thank you fpr you response PGriffith, I have a new question about it so I can’t use python script that I have in the root of my server, that is executed by the python interpreter and throw an answer, as I say this code throws me error because it does not get the path for example:

import commands
result=commands.getoutput(’/usr/bin/python tuapp.py’)

i have idea that can run script out de ignition and process reponse its posible?

You can use Execnet to call CPython from Ignition.
I’m using this successfull to call Numpy and machine learning libraries.
But be warned that this requires deep knowledge about Python / Jython differences, scoping and datatypes. It is definitely not an ‘out of the box’ solution. Execnet requires Jython 2.7, so this works only on Ignition 8.

PGriffith thanks i try this and tell you. Basically i need originate and check calls the asterisk pbx via REST that’s why I need to have a way to connect with ari rest library

any idea to include asterisk with ignition 8 without developing a module?

1 Like

This looks very interesting and I want to know so much more since there are optimization problems and more I would like to have Ignition do but every library I have thought it required were for C python or Python 3. Using Execnet, are you limited to python 2 or can you also use 3? Is there a setup guide or do you have any documentation for how you are using this in Ignition you could send me?

Hi,
we use ExceNet to run Python 3 in a Gateway Message Handler. The main concept of ExecNet is a channel to transfer data between the local and the remote python process. Here is a very basic example:

	import execnet
	group = execnet.Group()
	gw = group.makegateway('popen//python=python3.5')

	channel = gw.remote_exec("""
	    import numpy
	    array = numpy.array([1,2,3])
	    while 1:
	        x = channel.receive()
	        if x is None:
	            break
	        array = numpy.append(array, x)
	    channel.send(numpy.array_repr(array))
	""")
	
	for x in range(10):
	    channel.send(x)
	channel.send(None)
	y = channel.receive()
	
	group.terminate(timeout=1.0) # terminate popen python 3.5 process
	return y

To run ExceNet, you also need the apipkg package. In manually installed both in user-lib/pylib.

1 Like