Sikuli X: Want to use Jython 2.5.2 with sikuli-script.jar

Asked by RaiMan on 2011-01-13

*** this is a how to

current release: Jython 2.5.2 (final release available since March 3, 2011)
Download link: http://www.jython.org/downloads.html

Be aware, that some things might not behave as expected:
Sikuli is tested and runs with Jython 2.5.1

If you want to use it, you have to make sure, that in sys.path the pointer to Jython/Lib comes before the entry sikuli-script.jar/Lib (which is needed to find the Python layer of Sikuli using: from sikuli.Sikuli import *).

You should copy sikuli-script.jar to a place, so that the resulting absolute path does not contain any blanks and use this copy in the further steps (bug 702155)

There might be many ways to do the following (depending on your environment and goals), but this at least works:

--- e.g. you have Jython in c:\Jython2.5.2 and copied sikuli-script.jar to this directory

--- set the environment variable CLASSPATH as the path to sikuli-script.jar

--- set the environment variable JYTHONPATH
set JYTHONPATH=c:\Jython2.5.2\Lib;c:\Jython2.5.2\sikuli-script.jar\Lib

--- use the jython command file (Windows: jython.bat, Mac/Linux: jython) in Jython/bin to run a Sikuli script
e.g. you have a script at path-to/myscript.sikuli, you have to say:
jython.bat path-to/myscript.sikuli/myscript.py

--- comment on NetBeans/Eclipse:
If you use the Python plugins together with Jython 2.5.2 just check the generated sys.path in these environments at runtime of your script. It should be already in the correct sequence.

Question information

Language:
English Edit question
Status:
Solved
For:
Sikuli Edit question
Assignee:
No assignee Edit question
Last query:
2011-01-13
Last reply:
RaiMan (raimund-hocke) said : #1

*** this is a how to

surfdork (surfdork) said : #2

I dont understand how to configure Eclipse to use Sikuli from the instructions above.

What I need for Eclipse is enumerated steps. Eclipse is very tricky to configure, even for a seasoned developer.

I found these steps, unfortunatley I have no success following them

- installed Eclipse Helios Classic- installed the Plugin PyDev- installed Jython 2.5.1- made Jython the Interpreter in PyDev- in PyDev preferences -> PythonPath -> Ext.Libraries- a reference to sikuli-script.jar in the Sikuli program folder- a reference to the folder Lib/sikuli in the sikuli-script.jar (had to un-jar and copy the folder elsewhere)- in the script as first line:from Sikuli import *

So the question remains, is it even possible to use Eclipse with Sikuli and if so what are the working steps?

My options are to uninstall Win7x64 and replace with Win7x32 so I can continue to use Net Beans, which is a terrible IDE however it is usable.
Use another IDE. What other IDE supports using Sikuli in a x64 enviornment?

Traceback (most recent call last):
  File "C:\Users\mike\workspace\vcd_smoketest\src\test.py", line 1, in <module>
    from sikuli.Sikuli import *
ImportError: No module named sikuli

RaiMan (raimund-hocke) said : #3

the above instructions are not intended to explain, how Eclipse has to be configured.

It is for people who want to use Jython 2.5.2 for whatever reasons (as the title says).

coldtest (tesger) said : #4

hi,RaiMan ,I did not success, I download jython 2.5.2 and my sys.path is :
['D:\\script\\jy', 'D:\\jython2.5.2\\Lib', 'D:\\jython2.5.2\\sikuli-script.jar',
 '__classpath__', '__pyclasspath__/', 'D:\\jython2.5.2\\Lib\\site-packages']

I also set the jythonpath environment :
D:\script\jy>set jythonpath
JYTHONPATH=D:\jython2.5.2\Lib;D:\jython2.5.2\sikuli-script.jar

my classpath environment is :
D:\script\jy>set classpath
CLASSPATH=.;D:\jython2.5.2\sikuli-script.jar;D:\Program Files\Sikuli\sikuli-script.jar

my system path environment is :
D:\script\jy>set path
Path=D:\jython2.5.2\bin;d:\Ruby192\bin;D:\Python26\Scripts;D:\Python26\;d:\ruby\bin;C:\Program Files\PC Connectivity Solution\;C:\Program Files\ThinkPad\Utilities;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\Program Files\Intel\Wireless\Bin\;C:\Program Files\ThinkPad\ConnectUtilities;D:\Program Files\StormII\Codec\QTSystem\;C:\ProgramFiles\Microsoft SQL Server\80\Tools\Binn\;D:\jython2.5.2\bin;d:\jruby-1.6.1\bin;%APPDATA%\Python\Scripts;C:\Program Files\IDM Computer Solutions\UltraEdit\;E:\xampp\mysql\bin;D:\jdk1.6\bin;D:\Program Files\Sikuli\libs;C:\Program Files\Java\jre6\\bin

my jython code is :
import sys
from sikuli.Sikuli import *

print sys.path
Sikuli.capture()

when I run the scipt, I meet the error:

D:\script\jy>jython test.py
Traceback (most recent call last):
  File "test.py", line 2, in <module>
    from sikuli.Sikuli import *
ImportError: No module named sikuli

expect for your help ,thanks

coldtest (tesger) said : #5

I solved the problem ,but I don't know wether it is a good way
I unzip the sikuli-script.jar to C:\sikuli-script and modify the script as :

import sys
sys.path.append("C:\\sikuli-script\\Lib")
print sys.path

from sikuli.Sikuli import *

capture()

It is excuted successly :
D:\script\jy>jython test.py
['D:\\script\\jy', 'D:\\jython2.5.2\\Lib', 'D:\\jython2.5.2\\sikuli-script.jar', '__classpath__', '__pyclasspath__/',
 'D:\\jython2.5.2\\Lib\\site-packages', 'C:\\sikuli-script\\Lib']
[info] Sikuli vision engine loaded.
[info] Windows utilities loaded.
[info] VDictProxy loaded.

RaiMan (raimund-hocke) said : #6

@ coldtest:
Yes this is a solution, but not necessary to do so.

First sorry, for the mistake in the post (I corrected it):
JYTHONPATH=D:\jython2.5.2\Lib;D:\jython2.5.2\sikuli-script.jar\Lib

So you have the the correct sys.path as needed from beginning.
There is no need, to unzip sikuli-script.jar, since Jython accepts folder specifications inside of jar-files.

It is even possible to not copy sikuli-script.jar at all and use it at it's installation place (D:\Program Files\Sikuli\sikuli-script.jar in your case). The recommendation to copy it to another place was only, because it is not clear, whether the Jython problem with filenames containing blanks is fixed in 2.5.2. so you might give it a try.

One more thing:
CLASSPATH=.;D:\jython2.5.2\sikuli-script.jar
is sufficient - you do not need it twice.

coldtest (tesger) said : #7

wonderful, thanks to RaiMan so much ,you are so warm-hearted , I run my script succesly as what you told

Anirban (ani-chat82) said : #8

I got an Sikuli built on Win 7 64 bit platform. But while running some script from Eclipse, the problem I am seeing is, the JNI loader of Sikuli is not able to load the files Win32Util.dll and VisionProxy.dll. Hence it is showing the error " Access denied for Win32Util.dll" and throwing FileNotFoundException.

Did anyone of you come across this problem and find a workaround for this?....The most surprising part is the if I want to open Sikuli IDE in Win 7 64 bit platform, it is opening fine and also loading the vision engine when I am giving command to perform a click somewhere. But I need to use sikuli script written in java from eclipse. So just thought of asking this question before giving up the hope.

Anirban (ani-chat82) said : #9

With respect to my previous post, please find below the exception that is happening:

Exception in thread "main" java.lang.UnsatisfiedLinkError: org.sikuli.script.natives.VisionProxyJNI.new_FindInput__SWIG_0()J

Hi RaiMan

Could you please share the link fron where I could download Jython 2.5.2

Hi,

I tried the steps mentioned as above and i get following error message. Can anybody know what should i do to correct this.

[info] Windows utilities loaded.
Exception in thread "main" java.lang.UnsatisfiedLinkError: C:\Users\tjannan\AppData\Local\Temp\tmplib\VisionProxy.dll: Can't find dependent libraries
 at java.lang.ClassLoader$NativeLibrary.load(Native Method)
 at java.lang.ClassLoader.loadLibrary0(Unknown Source)
 at java.lang.ClassLoader.loadLibrary(Unknown Source)
 at java.lang.Runtime.load0(Unknown Source)
 at java.lang.System.load(Unknown Source)
 at com.wapmx.nativeutils.jniloader.NativeLoader.loadLibrary(NativeLoader.java:44)
 at org.sikuli.script.Finder.<clinit>(Finder.java:33)
 at org.sikuli.script.Region.doFind(Region.java:1029)
 at org.sikuli.script.Region$RepeatableFind.run(Region.java:1232)
 at org.sikuli.script.Region$Repeatable.repeat(Region.java:1203)
 at org.sikuli.script.Region.wait(Region.java:497)
 at org.sikuli.script.Region.find(Region.java:381)
 at org.sikuli.script.Region.getLocationFromPSRML(Region.java:1129)
 at org.sikuli.script.Region.click(Region.java:606)
 at org.sikuli.script.Region.click(Region.java:593)
 at org.sikuli.test_script.test01.main(test01.java:12)

RaiMan (raimund-hocke) said : #12

@ thuwan

additionally you need the standard Sikuli installation and its path settings:

--- Sikuli installed in e.g.
c:\Program Files\Sikuli X

--- and system path added
path-to-Sikuli\libs;path-to-java\jre6\bin

@RaiMan,

Thanks for the Help. Is there any Guidance Document that we can use to Code Sikuli advanced scripts using Eclipse. It would be great if you can share some of examples in the official site..

Regards,
Shiyam

RaiMan (raimund-hocke) said : #14

@ thuwan

There is no special document about using Sikuli with Jython directly or from inside Eclipse PyDev plugin.
All Sikuli script examples apply.

It is just Python programming with the special capabilities of using any Java classes directly.

The only additional aspects:
--- class-path and python-path settings according to the Sikuli docs
--- from sikuli import * needed even in the main script
--- you need an image concept for the captured images ( and might use the Sikuli IDE in parallel, to control the images ). The image support of import does not apply in this case, you have to use the image path feature.

Laanaya doha (dlaanaya) said : #15

Hello i'm new in sikuli and all the configuration.So i tried to do the configuration explained before but i'm stuck in the configuration of the classpath and the jythonpath, i don't know how to do so .
thank you for you're help