Problem importing the sikuli module into python

Asked by ilan

I'm having trouble getting sikuli+python unit testing to work, and would be glad for some assistance.
I searched the internet far and wide, but haven't anything that worked. My python knowledge is very limited, and I guess that doesn't help...

I'm using win7 32,
sikuli 1.0 rc3 (r905),
python 2.7.3

I'm trying to start running sikuli unit tests through python (not with command line, just as a python script to run with the python gui). I've followed, among others, the instructions shown here: http://sikuli.org/docx/globals.html
and here: https://answers.launchpad.net/sikuli/+faq/1804

my sikuli script (name: **slidelyChromeUnitTest2.sikuli**) starts like this (the rest doesn't matter becuase it gets stuck on the very first line):

    from sikuli import *
    import unittest

and my python script (name: **SikuliTestRunner.py**) looks like this:

    import sys

    mySikuliPath = "D:\\Program Files\\Sikuli X\\slidelyChromeUnitTest2.sikuli"
    if not mySikuliPath in sys.path: sys.path.append(mySikuliPath)

    import slidelyChromeUnitTest2

And what I get when I run the python script is this:

> Traceback (most recent call last): File
> "D:\Python27\SikuliTestRunner.py", line 6, in <module>
> import slidelyChromeUnitTest2 File "D:\Program Files\Sikuli X\slidelyChromeUnitTest2.sikuli\slidelyChromeUnitTest2.py", line 1, in
> <module>
> from sikuli import * ImportError: No module named sikuli

And I can't get past that error...
What am I doing wrong?

Thank you,
Ilan

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
pyCoder (validcode-ye) said :
#1

sikuli is Jython.... you can not use Cpython interperter. that is you problem. you should be using jython 2.5

http://www.jython.org/

the syntax is Python.... the interperter is Jython
http://sikuli.org/docx/devs/system-design.html

Revision history for this message
ilan (2-ilan) said :
#2

Hi.

Just tried downloading jython 2.5 and running the script through the command line:
jython pathToScript/SikuliTestRunner.py

got the exact same error...

Does that mean that it's not the answer? Maybe there's something else that needs to be done?

Thanks

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

No need to download anything - all is contained in Sikuli.

Look at faq 1804 for the unittest basics.

As a start, put all .sikuli scripts in one directory my-scripts and run the main-script.sikuli after going to that directory on command line with:

java -jar path-to-sikuli-script.jar main-script.sikuli

If you do it this way, the only thing needed is having "from sikuli import *" in every script, that is imported.
Sikuli's import support finds scripts to import in the same directory anyway.

Revision history for this message
ilan (2-ilan) said :
#4

Thanks RaiMan, that did it, the script is now working.

Revision history for this message
ilan (2-ilan) said :
#5

Thanks RaiMan, that solved my question.