Import python libraries

Thanks Kevin, I ll give this a try.

Hi Kevin and everyone

I did the procedure above, and it worked for all development/trial installations of Ignition I have. Windows and Raspberry Pi, Ignition 8.0.14 and 8.10. When I copied the packages for request into site-packages, Ignition seemed to take notice, gave me a dialog box for a moment, then would recognize the installed packages.

I then did this on my test server, Windows Server 2016, Ignition 8.0.14. Didn’t work. I copied from site-packages on my other Windows machine to C:\Program Files\Inductive Automation\Ignition\user-lib_202008171046\pylib\site-packages but it never gets recognized on the server.

Is there a step I’m missing? Or because the user-lib has a non-standard name?

Thanks for any help
Ken

Why and how did it end up with a different name?

I found out that Ignition was installed on the D: drive of this server, I was looking at an initial install that was kept for reference. Once I put it in the site-packages directory there it worked fine. Thanks for asking the question!

Ken

1 Like

Do you have any idea why the oauth2 module will not install using the steps you listed? I can install requests and a bunch of other libraries, but not this one. I have been racking my brain for the past week, it feels like I tried everything. Here is the error message I’ve been getting most recently:

C:\jython2.7.2\bin>jython -m ensurepip
e[33mDEPRECATION: A future version of pip will drop support for Python 2.7.e[0m
Looking in links: C:\Users\<user>~1\AppData\Local\Temp\tmp7jtdcw
Requirement already satisfied: setuptools in c:\jython2.7.2\lib\site-packages (41.0.1)
Requirement already satisfied: pip in c:\jython2.7.2\lib\site-packages (19.1)

C:\jython2.7.2\bin>jython -m pip install oauth2
e[33mDEPRECATION: A future version of pip will drop support for Python 2.7.e[0m
Collecting oauth2
e[31m  ERROR: Could not find a version that satisfies the requirement oauth2 (from versions: none)e[0m
e[31mERROR: No matching distribution found for oauth2e[0m
e[33mWARNING: You are using pip version 19.1, however version 20.3.4 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.e[0m

I also tried running pip install oauth2 from the C:\Jython2.7.2\bin directory, but that gives me this error:

C:\jython2.7.2\bin>pip install oauth2
e[33mDEPRECATION: A future version of pip will drop support for Python 2.7.e[0m
Collecting oauth2
  Using cached https://files.pythonhosted.org/packages/a0/6f/86db603912ecd04109af952c38bc08928886cf0e34c723481fa7db98b4b5/oauth2-1.9.0.post1-py2.py3-none-any.whl
Collecting httplib2 (from oauth2)
  Using cached https://files.pythonhosted.org/packages/ed/cd/533a1e9e04671bcee5d2854b4f651a3fab9586d698de769d93b05ee2bff1/httplib2-0.19.1.tar.gz
  Installing build dependencies ... e[?25ldone
e[?25h  Getting requirements to build wheel ... e[?25ldone
e[?25h    Preparing wheel metadata ... e[?25lerror
e[31m    ERROR: Complete output from command 'C:\jython2.7.2\bin\jython.exe' 'C:\jython2.7.2\Lib\site-packages\pip\_vendor\pep517\_in_process.py' prepare_metadata_for_build_wheel 'C:\Users\<user>~1\AppData\Local\Temp\tmpomshpc':e[0m
e[31m    ERROR: running dist_info
    creating C:\Users\<user>~1\AppData\Local\Temp\pip-install-c0uy_z\httplib2\pip-wheel-metadata\httplib2.egg-info
    writing dependency_links to C:\Users\<user>~1\AppData\Local\Temp\pip-install-c0uy_z\httplib2\pip-wheel-metadata\httplib2.egg-info\dependency_links.txt
    writing top-level names to C:\Users\<user>~1\AppData\Local\Temp\pip-install-c0uy_z\httplib2\pip-wheel-metadata\httplib2.egg-info\top_level.txt
    writing C:\Users\<user>~1\AppData\Local\Temp\pip-install-c0uy_z\httplib2\pip-wheel-metadata\httplib2.egg-info\PKG-INFO
    writing requirements to C:\Users\<user>~1\AppData\Local\Temp\pip-install-c0uy_z\httplib2\pip-wheel-metadata\httplib2.egg-info\requires.txt
    writing manifest file 'C:\Users\<user>~1\AppData\Local\Temp\pip-install-c0uy_z\httplib2\pip-wheel-metadata\httplib2.egg-info\SOURCES.txt'
    reading manifest file 'C:\Users\<user>~1\AppData\Local\Temp\pip-install-c0uy_z\httplib2\pip-wheel-metadata\httplib2.egg-info\SOURCES.txt'
    reading manifest template 'MANIFEST.in'
    warning: no previously-included files matching '__pycache__' found anywhere in distribution
    warning: no previously-included files matching '*.py[cod]' found anywhere in distribution
    writing manifest file 'C:\Users\<user>~1\AppData\Local\Temp\pip-install-c0uy_z\httplib2\pip-wheel-metadata\httplib2.egg-info\SOURCES.txt'
    creating 'C:\Users\<user>~1\AppData\Local\Temp\pip-install-c0uy_z\httplib2\pip-wheel-metadata\httplib2.dist-info'
    error: invalid command 'bdist_wheel'
    ----------------------------------------e[0m
e[31mERROR: Command "'C:\jython2.7.2\bin\jython.exe' 'C:\jython2.7.2\Lib\site-packages\pip\_vendor\pep517\_in_process.py' prepare_metadata_for_build_wheel 'C:\Users\<user>~1\AppData\Local\Temp\tmpomshpc'" failed with error code 1 in C:\Users\<user>~1\AppData\Local\Temp\pip-install-c0uy_z\httplib2e[0m
e[33mWARNING: You are using pip version 19.1, however version 20.3.4 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.e[0m

One of the reasons I thought might be causing it is that maybe oauth uses C libraries but that didn’t make much sense to me…

Any help would be appreciated. I found your post here and for a time, I was getting that same error message you specified there (until I reinstalled jython).

Whenever you use pip to install something and it has to “build” a dependency, it is C library.

Looks like the oauth2 dependency httplib2 switched to using c / binary wheel distribution sometime last year. (In version 0.18)

If you install httplib2's 0.17 version, you'll be able to also load oauth2.

pip install httplib2==0.17.4
pip install oauth2

Good luck! I haven't tried the oauth2 library myself, so it might have other dependencies that don't work in Jython (like multiprocessing, for example), but it's probably worth a shot!

(It should also be noted: If you're using Open ID Connect over oauth2 for Single Sign On, Ignition 8 has built-in IdP tools for that, of course. If you're running Perspective, OIDC from the Perspective application in the browser would be handled by Perspective itself, not scripts. I'd only look at using the Python oauth2 library if you're trying to do server-to-server oauth2 communication, or possibly something fancy with the WebDev/Web Services module.)

1 Like

Would be really cool in the future to have oauth2 functionality in Ignition for use in httpClient or elsewhere. I do a few integrations server-to-server to push/pull data into Ignition. oauth isn't to bad to do manually, but add this to a nice to have. Any java libraries for this type of thing?

3 Likes

Agreed!

I'm sure there are, but I haven't worked with any personally. When I've needed to do this in Ignition, I've done the same thing you mentioned (doing it manually: setting appropriate headers and doing the oauth handshake in Python).

+1!

Kevin, these instructions might need to be edited due to changes/deprecations on the pypi side.

Here is the output of my error when trying to pip search after a clean install.

Any recommendations are appreciated! In the meantime, I’m going to poke at different versions of pip.

–Edit to add version:
image

Just in case anyone wants to keep track of this Jython issue.

1 Like

Workaround Found!
Run a local mirror of pypi using devpi.
https://devpi.net/docs/devpi/devpi/stable/+d/quickstart-pypimirror.html
(still need to copy/paste from your local jython/Lib/site-packages to the ignition/user-lib/pylib/site-packages directory)

Edit: fleshed out ignition/site-packages path
Edit 2: removed docker container link - it was out of date. There are other docker containers out there.

2 Likes

Where would you recommend running this type of thing? Unofficially, of course. One place that comes to is a gateway time script that checks the status (whether it is started), and otherwise makes a ping to a health check endpoint and logs the result? But that doesn’t seem to work.

It depends on the route you want to go.

For Scenario 1 (doing it over web services), you’ll see a note in the guide:

“After [writing your script], you’ll need to set up your Python program as a service on the OS you’re running. There are many guides available online for this step. (In Windows, you can use Python’s pywin32 library. On Linux, this can be done by creating a service for systemd.)”

For Scenario 2 (invoking the os command line), reference the guide for that too. It has an example of passing arguments and getting results. When you do it this way, you’ll just be invoking that script on demand, so you wouldn’t need to monitor status or do anything else.

I’ve just updated the guide today, so the changes with that expanded example for Scenario 2 should be published shortly.

Good news on the pip front: The Jython devs got to the root of the SNI issue. I’ve updated the guide to include the fix, so pip can work again how it used to.

I just made the changes, so they should be published out shortly. https://support.inductiveautomation.com/hc/en-us/articles/360056397252-Python-In-Ignition

Check out the Using pip section.

2 Likes