Improting python script libraries in jython

Hi,

First of all how to import external libraries (packages) in gateway or client scripts in ignition.
Secondly can we import all python libraries (pypi) in jython?

Any help will be appreciated from scripting experts .

Regards
Prafull

The blog post at the following link says how to do that: http://www.perfectabstractions.com/blog/new-scripting-features-in-ignition-77-part-1#external-python-modules

Thanks for your reply nick. However my question was can I use the libraries given in Python Package Index page https://pypi.python.org/pypi using “pip install package” command and how to do that.

will appreciate any expert advise on that.

regards
prafull

Jython in Ignition doesn’t use any of the machinery the pypi expects for installing packages. You will have to manually install the packages you need into Ignition’s user-lib folders, and you can only install packages that have no ‘C’ dependencies.

2 Likes

It’s also worth noting that you’ll need Python 2.5 versions of the libraries you import. If you find a package that only has a version for Python 2.7, look back at older versions until you find a 2.5 version. If there is none, you either need to find an alternative package, or you might try converting the 2.7 package to 2.5 which can sometimes be a painful process.

If you really want to run a 2.7 library and go through the conversion process, try just running it first. You’ll normally hit syntax errors and you’ll need to convert those lines. Dictionary comprehensions are a common item you need to convert into loops, and there are a number of other items you’ll hit as well. 2.7 libraries also often have dependencies on other 2.7 libraries, so the whole process can be quite a bit of work. Even if you don’t hit syntax errors, there’s a chance the library might not work exactly how you expect in 2.5, so be sure to test thoroughly.

2 Likes

Thanks turmel. I will try to manually install it in user-lib-folders of Ignition. Hope its an easy process as simple as copying the compiled byte code of python into the folder! If there is any documentation on it somewhere in Ignition it or if you can explain exact steps involved, it will be great.

prafull

Thanks Kevin, you are a true expert on Jython scripting in Ignition. However I was wondering what prevents Ignition from supporting python 2.7 when already 3.0 has come! What is your road map for supporting the latest versions of python in Ignition ? Are they not available in Jython itself? This is especially a concern when python is getting more and more relevance in the AI world now a days and not being able to use the AI tools will be a big handicap!

Thanks again for the detailed reply once again and look forward to more details of your road map and future plan of supporting newer versions of python!

Best
Prafull

Pramanj, the implementation of Python that is used in Ignition is called Jython, which works with Java. The latest version of Jython is 2.7. That is why Python 3.0 is not used with Ignition, because that version of Jython does not exist.

Ignition does not use Jython 2.7 because that only works with Java version 8 and up. People still use Ignition with Java 6 and 7 for clients so Jython 2.7 can’t be used.

Inductive Automation plans to use Jython 2.7 in Ignition 8 and up. Here is a link to the feature request (made by yours truly): http://ideas.inductiveautomation.com/forums/255378-ignition-features-and-ideas/suggestions/7879431-upgrade-ignition-to-use-jython-2-7

1 Like

Hi Nick, thanks for the update. So its safe to use Python 2.5 version of whatever libraries we are trying to use in Jython right? (till such time that Ignition version 8 is released with Jython version 2.7 or higher). I need to see what version of python do the libraries that i intend to use, use.

Thanks a lot for the clarity.

Also please explain the steps required to install the new python libraries in Ignition.

regards
prafull

Does Ignition scripting support TCP/IP socket communication library functions? The system.net and the system.serial libraries seem to support only http get/put etc functions and rs232 serial port communication functions. How can I open a TCP/IP socket and wait for a communication with an eternal application on a separate thread ? Which library will support TCP/IP socket communication?

I just use the native java.net.* classes.

And java.nio.* classes, too, of course.

Where is it explained in the ignition user manuals how to use java.net.* classes. Any examples?

It’s not in the manuals. Using anything beyond what is offered by the system.* scripting functions is not an IA supported activity. It is an extension, a building upon the platform, made possibly by jython’s dual heritage of python and java. This would be where you search the web for java examples, and search the web for tips on accessing and extending java from jython. Consider starting here, with the tutorials, perhaps.

1 Like

Can you Please tell me how can I manually install ?
I m very new to ignition