Environment issue?

Perhaps not an Ignition issue, but hopefully someone can assist.
I am running a python application from Ignition and have a problem.
The app runs fine in Microsoft Visual Studio. The app uses a library "docplex".
When I run it from Ignition, it uses an old version (community edition == limited) of this library, but when I run it from VS it uses the correct full development version.
It looks like an environment issue. In VS, the environment is set up correctly within VS.
But when called from Ignition it must be using a different environment?
How do I select the environment when running from Ignition, or whatever, to resolve this issue?

Thanks in advance

  1. Ignition uses jython, not CPython, so the environment is totally different.

  2. Jython doesn't have v3.x.

  3. Jython cannot use any packages that have "C" dependencies, even indirectly.

Thank you @pturmel
You are correct
Ignition uses Jython and so can't run many packages

Projects that require these packages must be built EXTERNALY from Ignition, and executed via the runAction() method, as detailed in the documentation. That is precisely what my project is doing.

It works fine, EXCEPT:
When run from Microsoft Visual Studio (MS VS), it uses the python environment defined within MS VS. But when it is executed via runAction() from Ignition it uses a different (older) version of a dependent package.

So, what I would like some help on is how do I give a directive from within Ignition to the app to use a specific dependency.

My code is:

def runAction(self, event):
	
	import subprocess
	import os
	
	pythonPath = r"C:\Users\Ross\source\repos\PythonApplication1\env\Scripts\python.exe"
	scriptPath = r"C:\Users\Ross\source\repos\PythonApplication1\main.py"
	
	try:
		result = subprocess.check_output([pythonPath, scriptPath], stderr=subprocess.STDOUT)
		result_str = result.decode('utf-8')  
		system.perspective.print("Script output:", result_str)  
	except subprocess.CalledProcessError as e:
	    print("Script failed with error:", e.output)  

The printed error tells me that the wrong (older) dependent package is being used. That older package is also installed on same machine

Hope this clarifies.
Thanks again

OK, you need to inject environment variables into the execution environment. This is dirt simple with a proper API, like java's ProcessBuilder utility.

You'll have to figure out what environment variables are different when the gateway's service process spawns a child process versus your external testing. Ignition cannot get this from VS.

Some general comments:

  • Don't use jython's stdlib. Use java's stdlib. Up to date, non-buggy, not plagued with confusion over bytes versus strings, not plagued with character encoding, localization, and time zone bugs.

  • If you are using any import statement outside project library scripts, you are screwing up. Event action scripts (event scripts in general) should be one-liners delegating to a project library script function. Project library scripts can reliably import outside the the called function, and set up persistent constants, greatly reducing the code that must run every time the event/action happens.

  • Events (including actions) should run in a few milliseconds, or a hundred-ish milliseconds for direct operator command scripts. I don't know what you are trying to run, but if not something that gets a response nearly instantly, you should be looking at timer-moderated state machines or other offload techniques.

That sounds interesting
But that is not the issue
Apparently a separate run-time license is required for the package I am using