# Import python libraries

**URL:** <https://forum.inductiveautomation.com/t/import-python-libraries/8321>\
**Category:** General Discussion\
**Created:** [April 16, 2014, 3:25pm UTC](https://forum.inductiveautomation.com/t/import-python-libraries/8321 "2014-04-16T15:25:57Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![patricia.martin](https://avatars.discourse-cdn.com/v4/letter/p/7cd45c/32.png) [@patricia.martin](https://forum.inductiveautomation.com/u/patricia.martin)\
**Post date:** [April 16, 2014, 3:25pm UTC](https://forum.inductiveautomation.com/t/import-python-libraries/8321/1 "2014-04-16T15:25:57Z")

</div>

I’d like to import some Python libraries in order to add more functionability. Is it possible?

Thanks in advance

---

<div class="post-metadata">

**Author:** ![pdibenedetto](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pdibenedetto/32/6364_2.png) [@pdibenedetto](https://forum.inductiveautomation.com/u/pdibenedetto)\
**Post date:** [April 16, 2014, 3:46pm UTC](https://forum.inductiveautomation.com/t/import-python-libraries/8321/2 "2014-04-16T15:46:29Z")

</div>

> [@patricia.martin](#):
>
> Is it possible?

Right now, is not possible.

Consider the following things:

The scripting currently used in Ignition is Jython 2.5, not all the Python libraries (specifically those that are CPython library) are compatible: for more detail see [this](http://inductiveautomation.com/forum/viewtopic.php?f=70&t=10690)

There are a issue in the way that Ignition implements package/module organization for Jython that make that some jython code imported in app library that work outside ignition , not work inside: for more detail see [this](http://inductiveautomation.com/forum/viewtopic.php?p=38995)

If you need third-party funcionality, right now, the best way is using the java sdk and make available some java library in jython scripting.

Regards,

---

<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:** [April 16, 2014, 4:11pm UTC](https://forum.inductiveautomation.com/t/import-python-libraries/8321/3 "2014-04-16T16:11:07Z")

</div>

You also can import java classes to leverage your apps.

---

<div class="post-metadata">

**Author:** ![Kyle\_Chase](https://avatars.discourse-cdn.com/v4/letter/k/9de0a6/32.png) [@Kyle\_Chase](https://forum.inductiveautomation.com/u/Kyle_Chase)\
**Post date:** [April 16, 2014, 6:16pm UTC](https://forum.inductiveautomation.com/t/import-python-libraries/8321/4 "2014-04-16T18:16:05Z")

</div>

I believe 7.7 will have this functionality.

---

<div class="post-metadata">

**Author:** ![nmudge](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nmudge/32/3394_2.png) [@nmudge](https://forum.inductiveautomation.com/u/nmudge)\
**Post date:** [April 16, 2014, 7:55pm UTC](https://forum.inductiveautomation.com/t/import-python-libraries/8321/5 "2014-04-16T19:55:55Z")

</div>

Are you talking about importing modules that exist in [Python’s Standard Library](https://docs.python.org/2.6/library/)? You can import many modules that exist in Python’s Standard Library.

Here’s some documentation about the modules you can import using Jython 2.5:  
[jython.org/docs/library/indexprogress.html](http://www.jython.org/docs/library/indexprogress.html)

If you are talking about third-party Python libraries, you can copy and paste code from a third-party Python library into Ignition app modules. You will likely need to make scoping changes and change some names to use app.\* module names.

In some cases this can be done and work. I’ve seen it work a couple times.

Kyle is right that Ignition 7.7 will have a better way to add third-party Python libraries to Ignition.

---

<div class="post-metadata">

**Author:** ![patricia.martin](https://avatars.discourse-cdn.com/v4/letter/p/7cd45c/32.png) [@patricia.martin](https://forum.inductiveautomation.com/u/patricia.martin)\
**Post date:** [April 23, 2014, 11:20pm UTC](https://forum.inductiveautomation.com/t/import-python-libraries/8321/6 "2014-04-23T23:20:24Z")

</div>

so if it’s not possible and I decide to use The Ignition Module SDK, am I able to import external Java libraries?

---

<div class="post-metadata">

**Author:** ![nmudge](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nmudge/32/3394_2.png) [@nmudge](https://forum.inductiveautomation.com/u/nmudge)\
**Post date:** [April 23, 2014, 11:22pm UTC](https://forum.inductiveautomation.com/t/import-python-libraries/8321/7 "2014-04-23T23:22:42Z")

</div>

Yes

---

<div class="post-metadata">

**Author:** ![zackscriven](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/zackscriven/32/7213_2.png) [@zackscriven](https://forum.inductiveautomation.com/u/zackscriven)\
**Post date:** [August 4, 2014, 4:26pm UTC](https://forum.inductiveautomation.com/t/import-python-libraries/8321/8 "2014-08-04T16:26:19Z")

</div>

I would like to import a croniter 0.3.5 python library to do some cron time based scheduling.

would it be possible if someone could explain where and how I would import these .py files into Igntion’s directory and then be able to import them in a script. Attached is the package info.

Also if something like this already exists within ignition that would be a great help too.

Thanks - Zack  
[PKG-INFO.txt](https://us1.discourse-cdn.com/inductiveautomation/original/2X/6/6f9baa1904b1e71313a5b1dd886058235f9c329b.txt) (4.41 KB)

---

<div class="post-metadata">

**Author:** ![nmudge](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nmudge/32/3394_2.png) [@nmudge](https://forum.inductiveautomation.com/u/nmudge)\
**Post date:** [August 4, 2014, 4:59pm UTC](https://forum.inductiveautomation.com/t/import-python-libraries/8321/9 "2014-08-04T16:59:40Z")

</div>

Hi Zack,

Put the Python files in the user-lib/pylib directory where Ignition is installed. Then import the library into your scripts the regular Python way.

For example, in a Python script in Ignition:

```auto
from croniter import croniter
```

Best,

---

<div class="post-metadata">

**Author:** ![zackscriven](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/zackscriven/32/7213_2.png) [@zackscriven](https://forum.inductiveautomation.com/u/zackscriven)\
**Post date:** [August 4, 2014, 5:01pm UTC](https://forum.inductiveautomation.com/t/import-python-libraries/8321/10 "2014-08-04T17:01:10Z")

</div>

Thanks a million Nick!

---

<div class="post-metadata">

**Author:** ![nmudge](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nmudge/32/3394_2.png) [@nmudge](https://forum.inductiveautomation.com/u/nmudge)\
**Post date:** [August 4, 2014, 5:17pm UTC](https://forum.inductiveautomation.com/t/import-python-libraries/8321/11 "2014-08-04T17:17:08Z")

</div>

You bet!

---

<div class="post-metadata">

**Author:** ![bryce.troy](https://avatars.discourse-cdn.com/v4/letter/b/ecb155/32.png) [@bryce.troy](https://forum.inductiveautomation.com/u/bryce.troy)\
**Post date:** [December 9, 2014, 6:04pm UTC](https://forum.inductiveautomation.com/t/import-python-libraries/8321/12 "2014-12-09T18:04:56Z")

</div>

Joining this thread late, but I am trying to import the xlrd module in order to read one value once an hour from an existing excel spreadsheet. My short script runs fine in python, but I can’t figure out how to tie this into Ignition to run from a transaction group. I tried putting the xlrd folder in the user-lib/pylib directory, and also in the user-lib/pylib/site-packages directory. Then in the Interactive Script Tester I tried both “import xlrd” and “from xlrd import open\_workbook”, but it invariably returns “ImportError: cannot import name open\_workbook”. Can anyone point me in the right direction to make this work? Or maybe there is a better method to retrieve my excel value?? Thanks!

Bryce Troy  
Left Hand Brewing Company  
Longmont, Colorado

---

<div class="post-metadata">

**Author:** ![anna](https://avatars.discourse-cdn.com/v4/letter/a/779978/32.png) [@anna](https://forum.inductiveautomation.com/u/anna)\
**Post date:** [February 5, 2015, 4:26pm UTC](https://forum.inductiveautomation.com/t/import-python-libraries/8321/13 "2015-02-05T16:26:37Z")

</div>

Bryce,

Try the following:

1. find the “xlrd” directory that contains a file called **init.py** (this is the file that tells Python that the directory is to be treated as a Python package)
2. copy that directory into Ignition’s {installation directory}\Inductive Automation\Ignition\user-lib\pylib folder
3. In your code, your import statement and your calls will be (for example)

`from xlrd import file_name
filename.some_function()`  
where “file\_name” is the name of the .py file / module in the xlrd folder / package that contains “some\_function”

---

<div class="post-metadata">

**Author:** ![marioquark](https://avatars.discourse-cdn.com/v4/letter/m/22d042/32.png) [@marioquark](https://forum.inductiveautomation.com/u/marioquark)\
**Post date:** [February 4, 2016, 5:18pm UTC](https://forum.inductiveautomation.com/t/import-python-libraries/8321/14 "2016-02-04T17:18:35Z")

</div>

Since the jsonDecode builtin function works only for json arrays (not for json elements) (Ignition 7.6.7), I’m trying to place the [b]simplejson library /b in the gateway path.  
No one of my test worked, with `import simplejson as json` I always get the “ImportError: No module named simplejson”.  
Tried placing the dir there:  
user-lib/simplejson  
user-lib/pylib/simplejson  
with no luck.  
Any suggestion?  
Thanks

---

<div class="post-metadata">

**Author:** ![nmudge](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nmudge/32/3394_2.png) [@nmudge](https://forum.inductiveautomation.com/u/nmudge)\
**Post date:** [February 4, 2016, 6:30pm UTC](https://forum.inductiveautomation.com/t/import-python-libraries/8321/15 "2016-02-04T18:30:18Z")

</div>

Hi marioquark,

Putting Python libraries in the user-lib/pylib directory is an Ignition 7.7 feature.

Why do you say Ignition’s builtin system.util.jsonDecode function only works for json arrays? It should work for any json.  
Best,

---

<div class="post-metadata">

**Author:** ![liuwf2139](https://avatars.discourse-cdn.com/v4/letter/l/48db29/32.png) [@liuwf2139](https://forum.inductiveautomation.com/u/liuwf2139)\
**Post date:** [April 23, 2019, 8:11am UTC](https://forum.inductiveautomation.com/t/import-python-libraries/8321/16 "2019-04-23T08:11:24Z")

</div>

Hi,  
@nmudge I have seen all the questions about how to import python libraries to ignition in the forum, I find it troublesome to realize it. Now the ignition is Version 8.0, I doubt whether the software have improved better. If I’d like to use 3rd python or jython libraries in V8.0, can you give me some suggestion?

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [April 23, 2019, 12:31pm UTC](https://forum.inductiveautomation.com/t/import-python-libraries/8321/17 "2019-04-23T12:31:28Z")

</div>

If your external python library uses DLLs via CPython’s native interface, it will not (ever) work. If your external library needs python 2.7, you are in luck, as Ignition v8 has upgraded jython to 2.7.

---

<div class="post-metadata">

**Author:** ![Kevin.McClusky](https://avatars.discourse-cdn.com/v4/letter/k/47e85d/32.png) [@Kevin.McClusky](https://forum.inductiveautomation.com/u/Kevin.McClusky)\
**Post date:** [April 27, 2019, 1:09am UTC](https://forum.inductiveautomation.com/t/import-python-libraries/8321/18 "2019-04-27T01:09:29Z")

</div>

It’s also worth noting that we enabled python site-packages/ in Ignition 8. (Ignition/user-lib/pylib/site-packages)

What this means is that you can drop libraries in there to make them available in Ignition.

You can also use pypi / pip by doing the following:

Follow the **Using pip** section in the linked document here. [Python, Jython, CPython, Libraries, Pip, and Python 2.7 vs 3 - A quick primer](https://forum.inductiveautomation.com/t/python-jython-cpython-libraries-pip-and-python-2-7-vs-3-a-quick-primer/43201)

As others have mentioned, this doesn’t work for CPython specific packages that have native dependencies, but it does work for a whole slew of utility, parsing, and web libraries (things like AWS client libraries).

[Edited to reference the guidance doc with updated instructions.]

---

<div class="post-metadata">

**Author:** ![Alistair](https://avatars.discourse-cdn.com/v4/letter/a/f6c823/32.png) [@Alistair](https://forum.inductiveautomation.com/u/Alistair)\
**Post date:** [May 22, 2019, 8:56pm UTC](https://forum.inductiveautomation.com/t/import-python-libraries/8321/19 "2019-05-22T20:56:51Z")

</div>

Hi,  
I’m trying to get requests working. I’ve followed Kevin’s instructions above (a vertical learning curve for me!). I eventually made it to step 3, but when I try to run a gateway script with the first line:  
from requests import requests  
(Hopefully I’m doing this right). I’m getting an error:  
Caused by: org.python.core.PyException: Traceback (most recent call last): File “”, line 1, in File “C:\Program Files\Inductive Automation\Ignition\user-lib\pylib\site-packages\requests\__init_\_.py”, line 112, in from . import utils File “C:\Program Files\Inductive Automation\Ignition\user-lib\pylib\site-packages\requests\utils.py”, line 26, in from ._internal\_utils import to\_native\_string File “C:\Program Files\Inductive Automation\Ignition\user-lib\pylib\site-packages\requests\_internal\_utils.py”, line 11, in from .compat import is\_py2, builtin\_str, str File “C:\Program Files\Inductive Automation\Ignition\user-lib\pylib\site-packages\requests\compat.py”, line 31, in import json File "C:\Program Files\Inductive Automation\Ignition\user-lib\pylib\json\_init_.py", line 108, in from .decoder import JSONDecoder File “C:\Program Files\Inductive Automation\Ignition\user-lib\pylib\json\decoder.py”, line 24, in NaN, PosInf, NegInf = \_floatconstants() File “C:\Program Files\Inductive Automation\Ignition\user-lib\pylib\json\decoder.py”, line 18, in \_floatconstants _BYTES = ‘7FF80000000000007FF0000000000000’.decode(‘hex’) File "user-lib\pylib\encodings\_init_.py", line 142, in search\_function raise CodecRegistryError,\ encodings.CodecRegistryError: incompatible codecs in module “encodings.hex\_codec” (C:\Program Files\Inductive Automation\Ignition\user-lib\pylib\encodings\hex\_codec$py.class)

… 147 common frames omitted

The version of requests I have is 2.22.0

Any suggestions will be hugely appreciated!  
Thanks.

---

<div class="post-metadata">

**Author:** ![Kevin.McClusky](https://avatars.discourse-cdn.com/v4/letter/k/47e85d/32.png) [@Kevin.McClusky](https://forum.inductiveautomation.com/u/Kevin.McClusky)\
**Post date:** [May 26, 2019, 6:54am UTC](https://forum.inductiveautomation.com/t/import-python-libraries/8321/20 "2019-05-26T06:54:44Z")

</div>

Hi Alistair, a few questions:

1. Did you upgrade from a prior version of Ignition to Ignition 8? Which version of 8 are you running?
2. Can you try changing your first line to “import requests”? You shouldn’t need the “from requests” part.

I ask question 1 since some upgrades in the past from Ignition 7.9 left a few python directories around, which could have older versions of certain parts. I think we’ve resolved all of those issues in the latest version.

Just for reference, when you copy over the contents of site-packages from jython’s lib directory to Ignition’s for requests 2.22.0, you should be copying the dependencies as well. These are the ones I think requests needs: certifi, chardet, idna, urllib3.

[Next page](https://forum.inductiveautomation.com/t/import-python-libraries/8321.md?page=2)
