[1.1.0] problems trying to use jpype from Python

Asked by rita

After running next on Mac OS 10.10.3 error appeared:
Can this be solved?
Thanks

import sys
from jpype import *

def startJVM1():

    JVM = getDefaultJVMPath()
    startJVM(JVM, '-ea',"-Djava.class.path=sikulixapi.jar")
    java.lang.System.setProperty("java.awt.headless", "true");
    sikuli = JPackage("org.sikuli.script")
    login_window=sikuli.Pattern("edf_icon.png")
    window = sikuli.Screen()
    window.click(login_window)
    shutdownJVM()

if __name__ == "__main__":
    startJVM1()

[error] Can't initialize global Robot for Mouse: headless environment
[error] ***** Terminating SikuliX after a fatal error 999 *****
It makes no sense to continue!
If you do not have any idea about the error cause or solution, run again
with a Debug level of 3. You might paste the output to the Q&A board.
Traceback (most recent call last):
  File "/Users/Rita/Desktop/work/automation/sikuli/sikuli_test.py", line 16, in <module>
    startJVM1()
  File "/Users/Rita/Desktop/work/automation/sikuli/sikuli_test.py", line 11, in startJVM1
    window = sikuli.Screen()
  File "/Library/Python/2.7/site-packages/JPype1-0.6.0-py2.7-macosx-10.10-intel.egg/jpype/_jpackage.py", line 55, in __call__
    raise TypeError("Package {0} is not Callable".format(self.__name))
TypeError: Package org.sikuli.script.Screen is not Callable

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
RaiMan
Solved:
Last query:
Last reply:
Revision history for this message
RaiMan (raimund-hocke) said :
#1

well known restriction:

SikuliX does not work in a headless environment.

Needs a real screen or at least some X11 based screen simulation.

Revision history for this message
rita (fanrita) said :
#2

But in case I delete
 java.lang.System.setProperty("java.awt.headless", "true");
It seems that everything is stuck see http://screencast.com/t/8JLq7oamjzJ

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

no idea, what you are doing/using there, (looks like some overkill: starting a JVM from inside Python, to run some Sikuli statements?) but as far as I understand, try this:

import sys
from jpype import *

def startJVM1():

    JVM = getDefaultJVMPath()
    startJVM(JVM, '-ea',"-Djava.class.path=sikulixapi.jar -Djava.sikuli.Debug=3")
    #java.lang.System.setProperty("java.awt.headless", "true");
    sikuli = JPackage("org.sikuli.script")
    login_window=sikuli.Pattern("edf_icon.png")
    window = sikuli.Screen()
    window.click(login_window)
    shutdownJVM()

if __name__ == "__main__":
    startJVM1()

... and maybe, the shutdownJVM() comes too fast after the window.click???

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

... and this jpype stuff is a bit out of date ;-)

Revision history for this message
rita (fanrita) said :
#5

Traceback (most recent call last):
  File "/Users/margaryta/Desktop/work/automation/sikuli/sikuli_test.py", line 16, in <module>
    startJVM1()
  File "/Users/margaryta/Desktop/work/automation/sikuli/sikuli_test.py", line 10, in startJVM1
    login_window=sikuli.Pattern("edf_icon.png")
  File "/Library/Python/2.7/site-packages/JPype1-0.6.0-py2.7-macosx-10.10-intel.egg/jpype/_jpackage.py", line 55, in __call__
    raise TypeError("Package {0} is not Callable".format(self.__name))
TypeError: Package org.sikuli.script.Pattern is not Callable

Why it is out of date (I took the latest form git)

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

... and this jpype stuff is a bit out of date ;-)
ok, I looked at the original source forge project.
It now seems to be developed further here
https://github.com/originell/jpype

this is I guess where you got it from
thanks for the pointer. I have it now on my watch list ;-)

--- your problem:
TypeError: Package org.sikuli.script.Pattern is not Callable

... you are doing something wrong in the sense of jpype !?
Pattern("edf_icon.png")
is a Java constructor.
might be, that you need some "new" specifier??

... as mentioned - I do not know jpype and how it works (not yet ;-)

Revision history for this message
rita (fanrita) said :
#7

Hi,
Thanks a lot,
I found the problem very similar to my
http://sourceforge.net/p/jpype/support-requests/5/

I use jdk1.7.0_80.jdk

Please, suggest something

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

I just tried on my Mac to get jpype working.
no success, asking me to install Java 6 ( common problem with not mature Java apps ;-)
Sorry, but I have to stop here, since I do not have the time the next days, to check this on Windows.

Revision history for this message
rita (fanrita) said :
#9

ok. Thanks a lot

Revision history for this message
Yang (bluceyang) said :
#10

I just meet the same question, do you have any solution yet?