# Procedure for installing python libraries from source

**URL:** <https://forum.inductiveautomation.com/t/procedure-for-installing-python-libraries-from-source/26022>\
**Category:** Ignition\
**Created:** [June 21, 2019, 6:07pm UTC](https://forum.inductiveautomation.com/t/procedure-for-installing-python-libraries-from-source/26022 "2019-06-21T18:07:46Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dryhops](https://avatars.discourse-cdn.com/v4/letter/d/8797f3/32.png) [@Dryhops](https://forum.inductiveautomation.com/u/Dryhops)\
**Post date:** [June 21, 2019, 6:07pm UTC](https://forum.inductiveautomation.com/t/procedure-for-installing-python-libraries-from-source/26022/1 "2019-06-21T18:07:46Z")

</div>

While I understand that 3rd party scripts can be dropped into the user-lib/pylib folder, what is the proper way to import a more complex library that requires running ‘python setup.py install’, or is normally installed with a package manager? Do I first need to build it using a separate python installation and move the resulting files into pylib? Do I use the Distutils packaged with Ignition to build it using the python packaged with Ignition?

Specifically, I’m trying to get the install twilio (not the module, just the regular twilio python package) to support some legacy scripts. After downloading the source, I tried simply moving the twilio folder containing the scripts to user-lib/pylib on the gateway to no avail:

![Capture](https://us1.discourse-cdn.com/inductiveautomation/original/2X/7/75e8f3e6af7101d4f025b07b9c80358c46d5834a.png)

Thanks for your time.

---

<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:** [June 21, 2019, 7:07pm UTC](https://forum.inductiveautomation.com/t/procedure-for-installing-python-libraries-from-source/26022/2 "2019-06-21T19:07:39Z")

</div>

There’s actually a procedure you can use to use `pip` from within Jython to install packages, then link Ignition’s Jython lib to an-off-the-shelf Jython lib and use that…however, the article specifically calls out the `twilio` module as not working, because one of its dependencies, `cffi`, has C dependencies (IE, won’t work in Jython).

For posterity, here’s the procedure, copied verbatim from an internal document:  
0) On the server, install Java 8 if you haven’t already.

1. Download the full Jython 2.7.1 installer, and install. I installed to c:\jython2.7.1 for simplicity. Keep all other options default. Link: [http://search.maven.org/remotecontent?filepath=org/python/jython-installer/2.7.1/jython-installer-2.7.1.jar](http://search.maven.org/remotecontent?filepath=org/python/jython-installer/2.7.1/jython-installer-2.7.1.jar)
2. Make sure JAVA\_HOME points to the jre directory (tested with 8u191). If it’s not there, add the environment variable.
3. Open a CMD prompt in admin mode. (Not PowerShell) “cd” to the /bin
4. run “jython -m ensurepip” to install pip and setuptools
5. Shut down Ignition if it’s already running
6. In the CMD prompt, “cd” to the Ignition/user-lib/pylib folder
7. Delete the “site-packages” folder
8. Create a Junction link to the Jython site-packages directory: “mklink /J site-packages c:\jython2.7.1\Lib\site-packages”

---

<div class="post-metadata">

**Author:** ![Dryhops](https://avatars.discourse-cdn.com/v4/letter/d/8797f3/32.png) [@Dryhops](https://forum.inductiveautomation.com/u/Dryhops)\
**Post date:** [June 21, 2019, 7:56pm UTC](https://forum.inductiveautomation.com/t/procedure-for-installing-python-libraries-from-source/26022/3 "2019-06-21T19:56:54Z")

</div>

Thank you very much for the response. Exactly what I needed. Bummer about the twilio C dependencies. Would the java twilio API suffer from the same issues? I’m hoping I can maybe import a precompiled .JAR instead.

Cheers

---

<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:** [June 21, 2019, 8:06pm UTC](https://forum.inductiveautomation.com/t/procedure-for-installing-python-libraries-from-source/26022/4 "2019-06-21T20:06:34Z")

</div>

No, the Java package should be fine, although if you’re already loading a JAR it’s not _that_ much more work to just write a module that exposes some scripting functions.

---

<div class="post-metadata">

**Author:** ![sam.elawour](https://avatars.discourse-cdn.com/v4/letter/s/f0a364/32.png) [@sam.elawour](https://forum.inductiveautomation.com/u/sam.elawour)\
**Post date:** [November 10, 2020, 2:10pm UTC](https://forum.inductiveautomation.com/t/procedure-for-installing-python-libraries-from-source/26022/5 "2020-11-10T14:10:59Z")

</div>

Hi,  
I tried to follow these instructions and I got the following error when I ran “jython -m ensurepip” to install pip and setuptools:

Exception in thread “main” java.lang.UnsatisfiedLinkError: Could not load library. Reasons: [no jansi in java.library.path, The system cannot find the path specified]  
at org.fusesource.hawtjni.runtime.Library.doLoad(Library.java:182)  
at org.fusesource.hawtjni.runtime.Library.load(Library.java:140)  
at org.fusesource.jansi.internal.CLibrary.(CLibrary.java:42)  
at org.fusesource.jansi.AnsiConsole.wrapOutputStream(AnsiConsole.java:48)  
at org.fusesource.jansi.AnsiConsole.(AnsiConsole.java:38)  
at org.python.jline.AnsiWindowsTerminal.detectAnsiSupport(AnsiWindowsTerminal.java:57)  
at org.python.jline.AnsiWindowsTerminal.(AnsiWindowsTerminal.java:27)  
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)  
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)  
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)  
at java.lang.reflect.Constructor.newInstance(Unknown Source)  
at java.lang.Class.newInstance(Unknown Source)  
at org.python.jline.TerminalFactory.getFlavor(TerminalFactory.java:211)  
at org.python.jline.TerminalFactory.create(TerminalFactory.java:102)  
at org.python.jline.TerminalFactory.get(TerminalFactory.java:186)  
at org.python.jline.TerminalFactory.get(TerminalFactory.java:192)  
at org.python.jline.console.ConsoleReader.(ConsoleReader.java:243)  
at org.python.util.JLineConsole.install(JLineConsole.java:107)  
at org.python.core.Py.installConsole(Py.java:1744)  
at org.python.core.PySystemState.initConsole(PySystemState.java:1269)  
at org.python.core.PySystemState.doInitialize(PySystemState.java:1119)  
at org.python.core.PySystemState.initialize(PySystemState.java:1033)  
at org.python.core.PySystemState.initialize(PySystemState.java:989)  
at org.python.core.PySystemState.initialize(PySystemState.java:984)  
at org.python.util.jython.run(jython.java:263)  
at org.python.util.jython.main(jython.java:142)

Any help would be appreciated.

---

<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:** [November 10, 2020, 4:11pm UTC](https://forum.inductiveautomation.com/t/procedure-for-installing-python-libraries-from-source/26022/6 "2020-11-10T16:11:00Z")

</div>

Well, that’s a Jython problem, not an Ignition problem, but, it seems like the error is trying to tell you as much as it can. It looks like there’s some general bugs with `jansi` in Jython on Windows; there may not be much to do here other than investigate with Jython’s folks:  
[https://bugs.jython.org/issue2427](https://bugs.jython.org/issue2427)

---

<div class="post-metadata">

**Author:** ![scott.key](https://avatars.discourse-cdn.com/v4/letter/s/e480ec/32.png) [@scott.key](https://forum.inductiveautomation.com/u/scott.key)\
**Post date:** [June 14, 2021, 3:24pm UTC](https://forum.inductiveautomation.com/t/procedure-for-installing-python-libraries-from-source/26022/7 "2021-06-14T15:24:38Z")

</div>

Is this the same procedure when attempting the same from a Ignition 8.1.X system?(Currently looking at a 8.1.4, but you guys upgraded to java 11 for a bunch of stuff and I figured I would check)

---

<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:** [June 14, 2021, 3:57pm UTC](https://forum.inductiveautomation.com/t/procedure-for-installing-python-libraries-from-source/26022/8 "2021-06-14T15:57:34Z")

</div>

These instructions were written against 8.0, which also runs Java 11, and work fine. The Java installation is just for Jython’s `pip`, nothing to do with your actual Ignition system. You could also run Java 11 and I doubt it would cause any problems.

---

<div class="post-metadata">

**Author:** ![mdia](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mdia/32/87599_2.png) [@mdia](https://forum.inductiveautomation.com/u/mdia)\
**Post date:** [July 27, 2021, 1:21pm UTC](https://forum.inductiveautomation.com/t/procedure-for-installing-python-libraries-from-source/26022/9 "2021-07-27T13:21:16Z")

</div>

I tried all these steps and I was able to successfully install the desired package to jython. One issue I am having is that when I try importing from the package I installed (literally 1st line of my .py script) I get the following error:

File “C:\jython2.7.1\Lib\site-packages\serial\_ _init_ \_.py”, line 33, in  
from serial.serialjava import Serial  
File “C:\jython2.7.1\Lib\site-packages\serial\serialjava.py”, line 38, in  
comm = detect\_java\_comm([  
File “C:\jython2.7.1\Lib\site-packages\serial\serialjava.py”, line 32, in detect\_java\_comm  
raise ImportError(“No Java Communications API implementation found”)  
ImportError: No Java Communications API implementation found

Does this mean that Java does not have serial communications abilities? The package I want to use uses python’s pyserial package which I also installed.

---

<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:** [July 27, 2021, 1:46pm UTC](https://forum.inductiveautomation.com/t/procedure-for-installing-python-libraries-from-source/26022/10 "2021-07-27T13:46:58Z")

</div>

I don’t think Java had ever included an implementation of the comm API. It’s very old and has always been BYO implementation because it’s just an API to program against.

Something called rxtx used to be a popular implementation but I don’t know if it works any more.

---

<div class="post-metadata">

**Author:** ![mdia](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mdia/32/87599_2.png) [@mdia](https://forum.inductiveautomation.com/u/mdia)\
**Post date:** [July 27, 2021, 1:52pm UTC](https://forum.inductiveautomation.com/t/procedure-for-installing-python-libraries-from-source/26022/11 "2021-07-27T13:52:51Z")

</div>

> [@Kevin.Herron](#):
>
> comm API

So you don't think there's a way to use this package with Ignition/Jython?

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [July 27, 2021, 2:37pm UTC](https://forum.inductiveautomation.com/t/procedure-for-installing-python-libraries-from-source/26022/12 "2021-07-27T14:37:23Z")

</div>

> [@mdia](#):
>
> The package I want to use uses python’s pyserial package which I also installed.

pySerial uses DLLs which you can't use in Jython.

---

<div class="post-metadata">

**Author:** ![mdia](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mdia/32/87599_2.png) [@mdia](https://forum.inductiveautomation.com/u/mdia)\
**Post date:** [July 27, 2021, 3:01pm UTC](https://forum.inductiveautomation.com/t/procedure-for-installing-python-libraries-from-source/26022/13 "2021-07-27T15:01:45Z")

</div>

That’s unfortunate… My python script simply queries a serial device and outputs a result. Is there any way I can display this result in Ignition?

---

<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:** [July 27, 2021, 3:13pm UTC](https://forum.inductiveautomation.com/t/procedure-for-installing-python-libraries-from-source/26022/14 "2021-07-27T15:13:33Z")

</div>

The simplest option would probably be to use `system.util.execute` to launch your Python script directly and examine the result.  
Alternately, you could (purchase and) install the serial module for the appropriate scope (Vision client or gateway) and then adapt your script to use system.serial scripting functions - then everything is kept within Ignition and is somewhat more ‘portable’.

---

<div class="post-metadata">

**Author:** ![mdia](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mdia/32/87599_2.png) [@mdia](https://forum.inductiveautomation.com/u/mdia)\
**Post date:** [July 27, 2021, 3:49pm UTC](https://forum.inductiveautomation.com/t/procedure-for-installing-python-libraries-from-source/26022/15 "2021-07-27T15:49:04Z")

</div>

I am trying to use that function in the script console, but I am seeing no output. Here’s how I’m executing the function:

```auto
system.util.execute(["C:\\Python27\\python.exe","C:\\Users\\mdia\\Desktop\\test.py"])

```

Pretty sure I’m doing it wrong… How can I execute the python script using this function?

---

<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:** [July 27, 2021, 4:00pm UTC](https://forum.inductiveautomation.com/t/procedure-for-installing-python-libraries-from-source/26022/16 "2021-07-27T16:00:15Z")

</div>

Oh, right - `system.util.execute` is a 'fire-and-forget', it doesn't give you access to standard output. Try adapting this:

```python
from java.lang import ProcessBuilder, String

pb = ProcessBuilder([r"C:\Users\pgriffith\AppData\Local\Microsoft\WindowsApps\python3.exe", r"C:\Users\pgriffith\Downloads\test.py"])
process = pb.start()
output = String(process.getInputStream().readAllBytes())

print output

```

# (Note: This blocks until the process completes waiting on the input stream. It may or may not _ever_ complete, depending on what you're running, which could block a thread forever. Be careful).

---

<div class="post-metadata">

**Author:** ![mdia](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mdia/32/87599_2.png) [@mdia](https://forum.inductiveautomation.com/u/mdia)\
**Post date:** [July 27, 2021, 6:11pm UTC](https://forum.inductiveautomation.com/t/procedure-for-installing-python-libraries-from-source/26022/17 "2021-07-27T18:11:01Z")

</div>

I tried the following and it’s still not printing out an output.

```auto
from java.lang import ProcessBuilder, String

pb = ProcessBuilder([r"C:\Users\mdia\AppData\Local\Microsoft\WindowsApps\python.exe", r"C:\Users\mdia\Desktop\test.py"])

process = pb.start()

output = String(process.getInputStream().readAllBytes())

print output

```

Not working with python3 either. The script that I am testing with simply prints out a string.

---

<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:** [July 27, 2021, 6:30pm UTC](https://forum.inductiveautomation.com/t/procedure-for-installing-python-libraries-from-source/26022/18 "2021-07-27T18:30:33Z")

</div>

Where are you running this, and is the Python binary and test script located on the same machine?

That code worked fine for me in the Designer script console with some changes for my environment:

```python
from java.lang import ProcessBuilder, String

pb = ProcessBuilder([r"python", r"/Users/kevin/Desktop/test.py"])

process = pb.start()

output = String(process.getInputStream().readAllBytes())

print output

```

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/4/2/423a485d4003f90de8746bcafbd64c8795f66f12.jpeg)

---

<div class="post-metadata">

**Author:** ![mdia](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mdia/32/87599_2.png) [@mdia](https://forum.inductiveautomation.com/u/mdia)\
**Post date:** [July 27, 2021, 6:44pm UTC](https://forum.inductiveautomation.com/t/procedure-for-installing-python-libraries-from-source/26022/20 "2021-07-27T18:44:21Z")

</div>

> [@Kevin.Herron](#):
>
> Where are you running this, and is the Python binary and test script located on the same machine?

Running in the script console, and yes.

It finally worked for some reason after replacing the full python directory

“C:\Users\mdia\AppData\Local\Microsoft\WindowsApps\python.exe” with just “python”.

---

<div class="post-metadata">

**Author:** ![Corentin.appart](https://avatars.discourse-cdn.com/v4/letter/c/da6949/32.png) [@Corentin.appart](https://forum.inductiveautomation.com/u/Corentin.appart)\
**Post date:** [July 29, 2021, 1:06pm UTC](https://forum.inductiveautomation.com/t/procedure-for-installing-python-libraries-from-source/26022/21 "2021-07-29T13:06:12Z")

</div>

Hello all,  
it works in the script console but not in an script event, any idea ?

[Next page](https://forum.inductiveautomation.com/t/procedure-for-installing-python-libraries-from-source/26022.md?page=2)
