Scripting Console Error

I have seen some other posts for this issue and the most recent one was not resolved. I went through and uninstalled, cleared cache, reinstalled Jython, and I am at a loss.


Jython 2.7.1 (default:0df7adb1b397, Jun 30 2017, 19:02:43) 
[OpenJDK 64-Bit Server VM (Azul Systems, Inc.)] on java11.0.9

>>> ImportError: Cannot import site module and its dependencies: Error loading module DevceList: Traceback (most recent call last):
  File "<module:DevceList>", line 1, in <module>
NameError: name 'system' is not defined

Determine if the following attributes are correct:
  * sys.path: [C:\Users\rdlab\.ignition\cache\gw10.10.5.10_80\C0\pylib, C:\Users\rdlab\.ignition\cache\resources\platform\jython-2.7.1-ia5.jar\000000001498F8CC\Lib, __classpath__, __pyclasspath__/]
    This attribute might be including the wrong directories, such as from CPython
  * sys.prefix: C:\Users\rdlab\.ignition\cache\resources\platform\jython-2.7.1-ia5.jar\000000001498F8CC
    This attribute is set by the system property python.home, although it can
    be often automatically determined by the location of the Jython jar file

You can use the -S option or python.import.site=false to not import the site module

What do your project scripts look like? Do you have one named system or any other reserved name? Is it possible there’s a line in any of your scripts that’s reassigning system to something else? As in, system = xyz, inadvertently.

https://docs.inductiveautomation.com/display/DOC81/system.device.listDevices

was playing around with this and the only place it says system is in the system.device.listDevices

Do you have a script called DeviceList?

yeah I do.

Sorry, I hit reply before finishing…

EDIT: What are the contents of the script?

1 Like

I was trying to play with your script actually from here: system.device.listDevices() - specifying server? - #5 by JordanCClark

You have good taste. lol

Can you give a screen shot of where the script is located?

I was just trying it out in the console, it does send a single value to my dataset.

The error is implicating a project script library called DevceList [sic] - what you’re doing in the script console is unrelated to what’s actually causing the error.

1 Like

Yup look at that, just needed to nuke some scripts and all fixed.

2 Likes

I can start a new thread but just curious now that I have it all working.

[[u'Compact 5480', True, u'Connected', u'LogixDriver'], [u'SimValues', True, u'Running', u'ProgrammableSimulatorDevice'], [u'Moxa Port 502', True, u'Connected', u'ModbusRtuOverTcp']]

Why am I getting a u’ in front of 3/4 of the columns? Is that from ignition?

No, that’s a Python (2) ism. u in front of a string literal (you can also provide it yourself, e.g. myString = u'Λορεμ ιπσθμ δολορ' is valid code) means that it’s a “Unicode” string - normal Python strings can only hold the 255 characters in the standard ASCII range, which has obvious problems for internationalization/localization. Most Ignition APIs should default to returning Unicode strings.
As a consumer of the values in scripting, you shouldn’t ever really have to care; a Unicode string acts just like a “regular” ASCII string.

2 Likes

I faced this same issue, only with “system”, as in “system.util.getLogger”.

I had originally written the script on another server and copy-and-pasted the script to my new project. My guess is that there other hidden data attached to the script when copying from the Project Library to another. I copied the Project Script contents to NotePad++ → Deleted the Script from the Project Library → created a brand new Script with a slightly different Name (e.g. “amr_stats” to “amrStats”) → pasted the copied, old Script. Lo and Behold, the error messages disappeared.

I just upgraded to Ignition 8.1.17
I find it interesting that if I have a syntax error in my Project Library script, the Script Console displays the error.

ImportError: Cannot import site module and its dependencies: Error loading module GEO: NameError: name 'x' is not defined
Determine if the following attributes are correct:
  * sys.path: [C:\Users\lynn.martineau\.ignition\cache\gwotc-mesopc01_8088\C0\pylib, C:\Users\lynn.martineau\.ignition\cache\resources\platform\jython-ia-2.7.2.1.jar\00000000A5AE7F4C\Lib, __classpath__, __pyclasspath__/]
    This attribute might be including the wrong directories, such as from CPython
  * sys.prefix: C:\Users\lynn.martineau\.ignition\cache\resources\platform\jython-ia-2.7.2.1.jar\00000000A5AE7F4C
    This attribute is set by the system property python.home, although it can
    be often automatically determined by the location of the Jython jar file

You can use the -S option or python.import.site=false to not import the site module

In this case, I had an “x” in column 1 where a “def” would normally be.