Script editor error when working with python scripts

script-editor
jython
scripting
Tags: #<Tag:0x00007fa30c0378c8> #<Tag:0x00007fa30c0372b0> #<Tag:0x00007fa30c036b58>

#1

Using a simple python script on a windows 7 machine

print "hello"

upon execution I find the following in the console

console: Failed to install '': java.nio.charset.UnsupportedCharsetException: cp0.

Another error that I encountered (weirdly not every time) when opening this macro

(Fiji Is Just) ImageJ 2.0.0-rc-61/1.51n; Java 1.8.0_66 [64-bit]; Windows 7 6.1; 310MB of 50000MB (<1%)
 
java.lang.Error: Error: could not match input
	at org.fife.ui.rsyntaxtextarea.modes.PythonTokenMaker.zzScanError(PythonTokenMaker.java:881)
	at org.fife.ui.rsyntaxtextarea.modes.PythonTokenMaker.yylex(PythonTokenMaker.java:1081)
	at org.fife.ui.rsyntaxtextarea.modes.PythonTokenMaker.getTokenList(PythonTokenMaker.java:705)
	at org.fife.ui.rsyntaxtextarea.TokenMakerBase.getLastTokenTypeOnLine(TokenMakerBase.java:225)
	at org.fife.ui.rsyntaxtextarea.RSyntaxDocument.updateSyntaxHighlightingInformation(RSyntaxDocument.java:666)
	at org.fife.ui.rsyntaxtextarea.RSyntaxDocument.setSyntaxStyle(RSyntaxDocument.java:548)
	at org.fife.ui.rsyntaxtextarea.RSyntaxTextArea.setSyntaxEditingStyle(RSyntaxTextArea.java:2909)
	at org.scijava.ui.swing.script.EditorPane.setLanguage(EditorPane.java:501)
	at org.scijava.ui.swing.script.EditorPane.setLanguage(EditorPane.java:445)
	at org.scijava.ui.swing.script.EditorPane.setLanguageByFileName(EditorPane.java:433)
	at org.scijava.ui.swing.script.EditorPane.setFileName(EditorPane.java:379)
	at org.scijava.ui.swing.script.TextEditor.setEditorPaneFileName(TextEditor.java:1683)
	at org.scijava.ui.swing.script.TextEditor.open(TextEditor.java:1386)
	at net.imagej.legacy.plugin.DefaultLegacyEditor.open(DefaultLegacyEditor.java:92)
	at net.imagej.legacy.DefaultLegacyHooks.openInEditor(DefaultLegacyHooks.java:302)
	at ij.io.Opener.open(Opener.java)
	at ij.io.Opener.openAndAddToRecent(Opener.java:292)
	at ij.plugin.DragAndDrop.openFile(DragAndDrop.java:192)
	at ij.plugin.DragAndDrop.run(DragAndDrop.java:159)
	at java.lang.Thread.run(Thread.java:745)

On Mac OSx there are no error messages, but when running the macro nothing happens.
any ideas?

(@ctrueden :wink: )


Script editor error with python
#2

Seems to be related to this bug on windows (I had the same message a while ago in my app):

http://bugs.jython.org/issue2222

Try to pass the suggested JVM argument:

-Dpython.console.encoding=UTF-8

See:

Possibly the issue is fixed in 2.7.1 (I don’t need the flag anymore - no I have classpath problems;-))


#3

hi @Bio7

I saw that, but given the age of the bug, I hoped that it wouldn’t be this. Also it wasn’t an issue before…

thanks for the workaround


#4

Does the workaround -Dpython.console.encoding=UTF-8 work? If so, should we put that somewhere automatically?

Does it work with Jython 2.7.1? (You can test by cloning this project, changing the 2.7.0 to 2.7.1-rc3, building it, and using the resultant JAR in place of the old one in a Fiji installation.)


Script editor error with python
#5

hi @Bio7 and @ctrueden

Yes, launching fiji with the above arguments prevent the error bellow from appearing in the console

console: Failed to install '': java.nio.charset.UnsupportedCharsetException: cp0.

I also tried this suggestion above. The behavior is the same; error wihtout additional launch arguments and no error with the arguments.


But there is another problem: The following works: ``` print "hello" ``` But when structuring the script as bellow, nothing happens, no "hello", no error... nothing. This is the case with or without the launch arguments and also with the newer jython version. ``` def hello(): print "hello"

if name == “main”:
hello()

this breaks most of my scripts.

#6

Dear @FelixM,
I think it could be related to this issue:

solved that way by @imagejan

if __name__ in ['__builtin__', '__main__']:
    run_script()

hoping to be helpful,
Emanuele


#7
if __name__ in ['__builtin__', '__main__']:
    run_script()

yes, you are right @emartini, this does the tricks, with or without additional launch arguments and also for the 2.7.0 jython despite the mentioned console output bellow.

cheers!


#8

I am sorry to break your scripts.

We cannot go back to Jython 2.5.3 because it has critical memory leaks which were fixed in 2.7.0 (and besides, lots of people want 2.7.0 for various new features etc.).

We cannot go to 2.7.1 due to critical new performance problems, and anyway as you pointed out, 2.7.1 does not fix these new problems.

If anyone has patches which mitigate the issues (e.g., as hinted above, adding System.setProperty("python.console.encoding", "UTF-8") somewhere early), please contribute. My time is unfortunately booked solid through October.