[Bug] Iterable Python import

We are migrating a project from Ignition 7.9.3 to 8.
In our project we import the "SocketServer" library. When we try to do the same in Ignition 8, the following error occurs:

Traceback (most recent call last):
File "", line 1, in
File "C:\Users*.ignition\cache\gwlocalhost_80_main\C0\pylib\SocketServer.py", line 132, in
import socket
File "C:\Users*
.ignition\cache\gwlocalhost_80_main\C0\pylib\socket.py", line 3, in
from _socket import (
File "C:\Users***.ignition\cache\gwlocalhost_80_main\C0\pylib_socket.py", line 12, in
from collections import namedtuple, Iterable
ImportError: cannot import name Iterable

What do you suggest?
Thank you.

Ignition 8 has the latest version of jython, 2.7.1, instead of the ancient 2.5.3. You’ll have to replace external libraries with the appropriate newer version.

jython 2.7.1 should still have the Iterable class in the collections module… something else might be going on. /-:

I was able to import and use SocketServer in the script console of the current 8.0 build. Due to changes in the jython library, it looks like you might be running into a cached version. Try deleting your .ignition cache, relaunch the designer/project and let us know if that resolved your issue.

Might also be worth trying the import in the script console in the designer to see if the same error occurs.

Also, make sure you’re running the latest 8 build. The first release of the 8 beta had Jython 2.7.0, which had problems with the python socket library.

Thank you.
Unfortunately the error is still present: I have deleted the cache, relaunched the designer and tried to import the library. This is the screenshot of the script console:

What 8.0 build version are you using?

I’m also getting the same error.

Build: 8.0.0-beta0 (b2018112202)

I also cleared the ignition cache before trying.

8.0.0-beta0 (b2018112002)

I am unable to duplicate this on the latest build on my Windows 10, Linux and Mac clean OS + clean Ignition installations. Is it possible to try the following just to be sure that everything is current?:

  1. Update to the latest 8.0 nightly version
  2. Download an install the latest version of the Client Launcher to ensure you have the latest Java code (we did have some issues with earlier versions of Java and our implementation of Jython)
  3. Delete everything in your %USERPROFILE%\.ignition\cache directory
  4. Open the Designer and try to import the library again in the Script console

Thanks,
Garth

Hi Garth,

The error seems to be specific to the collections module - it can’t import the Iterable class.

The _socket.py file calls for this class on Line 12.

I’m not sure if this is an Ignition bundled python file or if I have included it myself.

Cheers
Dan

I suspect you have leftover customizations somewhere. That import works for me with build b2018111902.

Thanks @pturmel, i’ll clean install Ignition and the caches and hopefully my hidden customisations go away.

An early build of Ignition 8 accidentally had two copies of collections, one that was a holdover from Jython 2.5, and one that’s the new one for Jython 2.7. I’m guessing you’re running into that issue.

Old one: <ignition_install_dir>/user-lib/pylib/collections (directory)
New one: <ignition_install_dir>/user-lib/pylib/collections.py (file)

Python has the unfortunate (in this case) behavior of defaulting to looking in directories before looking in .py files for imports. This means the old folder is used, even if it doesn’t have the classes that the script needs inside.

In theory installing a later version of 8 beta would have cleaned up the old directory, but I’m guessing somehow that didn’t happen, and that folder is still there.

If the “collections” directory is still there in pylib, feel free to rename it or move it out of that directory. Ignition has a file monitor on that directory so it’ll know as soon as the change is made and will propogate it to any open designer and client nearly instantly. After you move that out, wait 30 seconds and try again.

(As a sidenote, if it’s working properly, collections.py will import _abcoll.py, which adds Iterable to collections and makes it import-able.)

4 Likes

Thanks Kevin, that was the case. I had a directory called collections and the collections.py file at the same time. The upgrade to the new nightly didn’t get rid of the directory but a clean install did.
The class imports properly now.

Thanks

2 Likes

Thank you very much: the import works properly also on my side.

1 Like