How we import sikuli.Sikuli.* module in python

Asked by Durga Anneboyina

Hi,
    We would like to do the Automation using Sikuli and we have to run the .py files in Sikuli from the Cammand line using Python.
But it show an error : 'click() and other sikuli functions are not found'.
     So, we tried to import Sikuli modules but we did't get.
This is one question and another one is, for running the python script is it requires any path and class paths.
Plz help these questions, i am new for the Sikuli and python.

Thank you.

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

my comment at question https://answers.launchpad.net/sikuli/+question/136013 fits here again:

You need Jython (Python implemented on Java) to run the .py script. It is Python language, but it is not possible to run them with a Python interpreter.

I have installed my own Jython (you may use the Jython that comes with Sikuli).

If you run Sikuli scripts "outside" the IDE you have to insert at the beginning:
import * from sikul.Sikuli
The sikuli-script.jar has to be in the classpath.

I use the following shell script on my Mac (should be same on Linux) to run my scripts "standalone":

#!/bin/sh
JYTHONDIR=path-to/jython.jar
SIKULI=path-to/sikuli-script.jar
SCR=$1
shift
java -cp "$JYTHONDIR:$SIKULI" org.python.util.jython "$SCR" $@

On Windows it should be similar.

Revision history for this message
Durga Anneboyina (durga-anneboyina) said :
#2

Hi,
     Thanks for giving me reply. I installed jython_installer-2.5.1 on windows and set the path and class path for the jython like java.
      I wrote the code as fallows,
          #!user/bin/jython
          JYTHONDIR=C:\\jython2.5.1\\jython.jar
          SIKULI=C:\\Program Files\\Sikuli\\sikuli-script.jar
          SCR=$1
          shift
          java -cp "$JYTHONDIR:$SIKULI" org.python.util.jython "$SCR" $@
But i get the Error: mismatch character '\' excepting '\n'
could u Please send me the code of jython on windows.
and another thing is, if we import sikuli.Sikuli.* it shows now module found.
Please help me for this
Thank you.

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

1. Sorry for the wrong import statement, should be:
from sikuli.Sikuli import *

2. The script is for Mac/Linux and has to be "translated" to Windows batch (e.g. %SIKULI% instead of $SIKULI and other things)

Revision history for this message
Durga Anneboyina (durga-anneboyina) said :
#4

Hi,
   Thanks for giving me reply. I tried with
from sikuli.Sikuli import *
But i get the Error: 'mismatched input " * " expression set null.
and also kindly explain me about SCR=$1 and how it should be placed in windows.
could you please explain me what is happening exactly in above program.
Thank you.

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

1. no double \ in cmd files

2. your callJython.cmd should look like this: (long time ago, since my last .cmd ;-)

set JYTHONDIR=C:\jython2.5.1\jython.jar
set SIKULI="C:\Program Files\Sikuli\sikuli-script.jar"

java -cp "%JYTHONDIR%:%SIKULI%" org.python.util.jython %*

usage: callJython.cmd myscript.py parm1 parm2

the apostrophes with SIKULI are needed because of the intervening blank
%* means all parameters given on commandline (first parameter the script)

the construct (translated to windows .cmd)
SCR=%1
shift

and
java -cp "%JYTHONDIR%:%SIKULI%" org.python.util.jython "%SCR%" %*

might be needed if you use scripts with full path specified and this contains blanks

3. the myscript.py:
from sikuli.Sikuli import *
# your script statements

hope it helps ;-)

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

ok, I tested and found out, that just "translating" does not work.

the following works on Windows:

set the both environment variables:
set JYTHONPATH=c:\Program Files\Sikuli\sikuli-script.jar\Lib
set CLASSPATH=c:\Program Files\Sikuli\sikuli-script.jar

and use the jython.bat to run from a directory that is writeable

C:\jython2.5.1\bin\jython.bat path-to-your-script.py parm1 parm2

Revision history for this message
Durga Anneboyina (durga-anneboyina) said :
#7

Thank you for giving me quick reply.
I tried with another way i get the result. i.e; extract the sikuli-script.jar files of sikuli and paste those files in Lib of jython2.5.2 RC2.
And copy the templib files of sikuli into the templib of jython2.5.2 RC2.
set the path for the templib of jython2.5.2 RC2 and
set the classpath for the lib of jython2.5.2 RC2.
then i get the result.

Thank you for help me.