[2.0.5] Python script containing non-ASCII (code or comment) runs in IDE, but not as exported jar --- fixed in 2.0.6

Asked by Matteo Acquarone

---------------------------------------------- background - no workaround - fixed in 2.0.6
Python scripts containing non-ASCII characters (in code and/or comments) need as 1st or 2nd line
# code: utf-8
to compile correctly (or any other accepted version of this line) - this one is the shortest

In IDE, when running a script, this and some more code is added to the front of the script.

When exporting to a jar, the pre-compile actions add 2 lines at the top, but not the code-comment. So even if your code has the needed code-comment as 1st or 2nd line, it moves to the 3rd or 4th line and is not accepted.
Since currently compile errors simply skip the script-file without any comment, we have the mentioned situation.

There is no workaround in 2.0.5, but it is fixed in 2.0.6 (a code-comment for utf-8 is added and the addition is only one line).

The jar-export will be enhanced further having more options and be more verbose in case of problems.

---------------------------------------------------------------------------------

Hello,
I had a script that was running ok if launched from the IDe but if, after generating runnable jar, launching it from commandline was failing.
The script is using OCR and the tessedit_char_blacklist that contains some char that I don't want to be found, like "£".
I cut away anything that worked and I got this minimal script that exhibits the problem:

#!/usr/bin/python
# -*- coding: utf-8 -*-
popup("£")

When launched from the IDE the popup shows "£", but the executable generated jar does not contain the script class and so it doesn't works.
i.e. If the pop-up contains something like "x" the executable jar contains these folder and files:
META-INF\
org\
__main__$py.class
__run__$py.class
TestNoCmd$py.class
and works if launched from commandline.
If the popup contains the "£" char the TestNoCmd$py.class file disappears from the jar and with the same commandline it doesn't works.

.... deleted

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
Matteo Acquarone
Solved:
Last query:
Last reply:
Revision history for this message
Matteo Acquarone (matteoa2) said :
#1

Hi all,
another finding:
the problem is also present if the £ char is in a comment, and not in a runnable part of the script, e.g. this script works from the ide but not from the commandline:

#!/usr/bin/python
# -*- coding: utf-8 -*-

popup("x")

Revision history for this message
Matteo Acquarone (matteoa2) said :
#2

HI,
another bit of hopefully useful information: I noticed that when trying to export the executable jar file there is this message in the IDE:
"SyntaxError: ("Non-ASCII character in file 'C:\\Users\\MyUser\\AppData\\Roaming\\Sikulix\\SikulixStore\\SikulixTemp\\scriptCompiled\\DaimlerTool.py', but no encoding declared; see http://www.python.org/peps/pep-0263.html for details",)"
As can be seen from the example script above there is the coding accordingly to the pep-0263
I made a test with the other possible format with the same (bad) result both on the message panel and of the missing .class file into the jar.
These are the formats I've tested:
# This Python file uses the following encoding: utf-8
and
#!/usr/local/bin/python
# coding: utf-8
Both on the very first line of the script.
It seems "as if" for some reason the compiler is not able to find the conding message.
Hope this helps to find a solution..
Thanks

Revision history for this message
Matteo Acquarone (matteoa2) said :
#3

HI,
I found a workaround for this problem, that is to embed into the script folder a text file with the desired characters, read the file at runtime and then use the file content as the tessedit_char_blacklist for Tesseract.
I'm ok with that workaround, but if a better solution exists I'd be glad to test it!

Revision history for this message
Launchpad Janitor (janitor) said :
#4

This question was expired because it remained in the 'Open' state without activity for the last 15 days.

Revision history for this message
Matteo Acquarone (matteoa2) said :
#5

Hi, any news regarding this?
In the meantime I've tested also with the latest sikulixidewin-2.0.6-20220817.114540-15 and my problem is still there.
Is this a known bug?

Revision history for this message
Launchpad Janitor (janitor) said :
#6

This question was expired because it remained in the 'Open' state without activity for the last 15 days.

Revision history for this message
Matteo Acquarone (matteoa2) said :
#7

HI, does this has happened only to me or is a known problem?

Revision history for this message
RaiMan (raimund-hocke) said :
#8

have to check.
sorry for delays even in future

Revision history for this message
Matteo Acquarone (matteoa2) said :
#9

Hi RaiMan,
thanks for the answer, and don't worry for delays, your support has always been so prompt that is not a problem...

Revision history for this message
Matteo Acquarone (matteoa2) said :
#10

Thanks RaiMan!