Install user library

Hello,

I want to install this library pythonnet below. Actually I want to call a .net dll library in a pyhon script. So after some search, I found this library but having difficulty installing this pythonnet library.

I followed the steps that are mentioned in this forum post below. I was able to create a junction link between ignition library directory and jython library directory.

But I am having difficulty installing the library in jython using pip. What commands should be ran?

I also tried using python command but still getting errors as shown in screen capture below. How this error can be fixed?

I also tried copying the library folder in this directory C:\Program Files\Inductive Automation\Ignition\user-lib\pylib. But still getting import error in script.

Appreciate any help.


Fairly certain that is CPython and you won’t be able to use it with Jython/Ignition.

1 Like

If the setup.py file for a given pypi package includes a build phase, that pretty much always means part of the package is written in C. This will not be jython-compatible. So too for any dependencies automatically pulled in by a package.

Key graf from the knowledgebase article:

Because Ignition’s Python interpreter is Jython, that means unlike CPython, Java libraries are accessible. It also means C libraries aren’t accessible.

{ Emphasis added. }

1 Like

As folks have mentioned, that library won’t be available in Ignition’s Python environment (Jython), since it’s a CPython library.

For your overall goal, the most popular ways to invoke DLLs from Ignition:

Option 1: Run CPython next to Ignition. See the " Can I run Python 3 code from Ignition?" section from the article WillMT10 linked.

Option 2: Create an Ignition module that calls that library using JNA. An example module exists that you can download and use as a starting point.
GitHub Ignition JNA Example
Note that if it’s a pure .NET library that doesn’t have C linkage, you might need to go through a few steps first, as mentioned in the readme.

3 Likes

Thank you all for your help and for sharing useful article and information. I will try the 2 options that are mentioned.

What about using Javonet as a method to call .NET dll within Ignition. I think they are based on the JNA, but not 100% sure.

I have a project where we have a specialized instrument that is only available through their own .NET dll. I am looking for a solution to possibly use a trigger from the PLC to trigger the calls to the DLL to run the instrument and return data.

Ultimately, the data is used in Ignition and the PLC. So I would love to do all this in Ignition and avoid writing a custom web service, .NET application or Python app.

I think this would require that a client can make the DLL call (not on the ignition gateway)

There are two common ways to call a DLL from Ignition:

  1. Wrap the DLL with web services. If using Visual Studio, this is easy. This video is one option of how to accomplish this. It’ll create a service that starts with the OS, making that dll available to be called over web services. WCF Services - How to create a simple WCF Service - Part 1 - YouTube This is normally the preferred way for .NET DLLs.
  2. Use JNA from inside Ignition to call the DLL. Doing this requires writing an Ignition module, and we (IA) have put together a module that you can use as a starting point showing how to do this. GitHub - IgnitionModuleDevelopmentCommunity/JNAScriptingFunction: The JNA (Java Native Access) Example module provides users with two examples for using a Dynamic Link Library (DLL) in Ignition Pay attention to the note " Need to use a DLL written in C#?" about using C# DLLs in that github documentation, since they’re a bit trickier to use than traditional DLLs, which are normally really straightforward.

You mentioned preferring not to write a “custom web service”, so option 2 might be your best bet.

All that said, I haven’t used Javonet myself, but you might be able to write a module that would use that as well. If Option 2 above turns out not to be a good option for whatever reason, you could certainly write a module that would include your purchased copy of the Javonet Jars and then could program against their API.

Edit: Since you mentioned “I think this would require that a client can make the DLL call (not on the ignition gateway)” - Option 2 might be the way to go, since it wouldn’t be easy to do Option 1 with distributing a web service to each client. Using Option 2 and adding the DLL calls in the Client context in the module would let you do your DLL calls from a Vision Client, so it would be running directly on the client rather than the Gateway.