ImportError: no module named sikuli --- sikulixapi.jar not on Java classpath

Asked by Dave Kane on 2018-12-06

I am getting an error when I attempt to run a python script (jython dak2.py). I've tried for a while to get to the bottom of this, to no avail and don't know what to do next. Any ideas?

I’m running CentOS release 7.5 on a VMWare Workstation VM and Sikuli 1.1.4

I’m able to run the SikuliIDE and created a sample script where I’m able to execute multiple commands on the CentOS desktop

I’ve saved the script off to a folder (/home/admin/Sikuli/scripts/dak2.sikuli) containing the .png files and the .py python script

I want to run the python script (dak2.py) from the command line
 I’ve edited the python script and added the following 2 lines to the top of the file
  import org.sikuli.basics.Debug
  from sikuli import *
 when I run the command “jython dak2.py” I get an error:
  Traceback (innermost last):
   File “dak2.py”, line 1 in ?
  ImportError: no module named sikuli

Thanks in advance

Question information

Language:
English Edit question
Status:
Answered
For:
Sikuli Edit question
Assignee:
No assignee Edit question
Last query:
15 hours ago
Last reply:
1 hour ago
RaiMan (raimund-hocke) said : #1

the intro statements for standalone .py scripts is
import org.sikuli.script.SikulixForJython
from sikuli import *

... and sikulixapi.jar has to be on the classpath.

sorry, but the docs for that are a bit hidden ;-)
https://github.com/RaiMan/SikuliX-2014/wiki/Jython-in-IDEs-like-Eclipse-or-running-it-from-commandline

For running scripts from commandline simply use this command:
java -jar <path-to>/sikulix.jar -r <path-to>/myscript.sikuli

for the available parameters see:
https://sikulix-2014.readthedocs.io/en/latest/faq/010-command-line.html

Dave Kane (dak204) said : #2

RaiMan,

Thanks for the speedy reply. I would like to use python to execute the scripts, extending what is generated by Sikuli during the save process as it packages/includes the .py and .png files. I'm currently running the command "jython dak2.py" which is generating the ImportError. Is it possible to run the python script to execute sikuli?

David

RaiMan (raimund-hocke) said : #3

--- Is it possible to run the python script to execute sikuli?
... yes, but at least this has to be obeyed (see comment #1)
the intro statements for standalone .py scripts is
import org.sikuli.script.SikulixForJython
from sikuli import *
... and sikulixapi.jar has to be on the classpath.

... and finally you have to solve the "where are the images loaded from" problem (imagePath).

--- extending what is generated by Sikuli during the save process
not sure what you mean by that?

Dave Kane (dak204) said : #4

RaiMan,
Thanks, you have been very patient with me and I appreciate it. I am trying to run the python code, in this case dak2.py, that gets created when you save from the IDE. I have set the classpath properly (a linux which sikuli.jar/sikulixapi.jar finds the files in the /home/admin/Sikuli directory, which also has the directory dak2.sikuli directory containing the image files and the python script) yet still get the same outcome. Could it be an issue with the directory structure I'm using, capitalization of the filenames? I aware of some dependencies associated with where the various sikuli files are located.

David

      From: RaiMan <email address hidden>
 To: <email address hidden>
 Sent: Friday, December 7, 2018 3:57 AM
 Subject: Re: [Question #676645]: ImportError: no module named sikuli

Your question #676645 on Sikuli changed:
https://answers.launchpad.net/sikuli/+question/676645

    Status: Open => Answered

RaiMan proposed the following answer:
the intro statements for standalone .py scripts is
import org.sikuli.script.SikulixForJython
from sikuli import *

... and sikulixapi.jar has to be on the classpath.

sorry, but the docs for that are a bit hidden ;-)
https://github.com/RaiMan/SikuliX-2014/wiki/Jython-in-IDEs-like-Eclipse-or-running-it-from-commandline

For running scripts from commandline simply use this command:
java -jar <path-to>/sikulix.jar -r <path-to>/myscript.sikuli

for the available parameters see:
https://sikulix-2014.readthedocs.io/en/latest/faq/010-command-line.html

--
If this answers your question, please go to the following page to let us
know that it is solved:
https://answers.launchpad.net/sikuli/+question/676645/+confirm?answer_id=0

If you still need help, you can reply to this email or go to the
following page to enter your feedback:
https://answers.launchpad.net/sikuli/+question/676645

You received this question notification because you asked the question.

RaiMan (raimund-hocke) said : #5

please paste your relevant environment settings for Jython and Java.

How do you run the script exactly?
is the Jython/bin on path?

Again: why do you do that? why don't you use the features of SikuliX?

Dave Kane (dak204) said : #6

RaiMan,
I execute the script from the command line via jython dak2.py.
I want to remote into a box and kick off the python script to run the test that executes a GUI.

I ran typescript to capture the settings, commands and output from the session, see below - I hope this helps
----------------------------
[admin@RFC1918 ~]$ who am i
admin    pts/10       2018-12-10 08:50

[admin@RFC1918 ~]$ pwd
/home/admin

[admin@RFC1918 ~]$ ls -l
total 4380
drwxr-xr-x. 2 admin admin       6 Nov 30 09:33 Desktop
drwxr-xr-x. 2 admin admin       6 Nov 30 09:33 Documents
drwxr-xr-x. 5 admin admin     192 Dec  7 15:26 Downloads
rw-rw-r--. 1 admin admin       0 Dec 10 08:50  for_raiman
drwxr-xr-x. 9 root  root      107 Nov 30 10:04 jdk-10.0.2
drwxr-xr-x. 2 admin admin       6 Nov 30 09:33 Music
drwxrwxr-x. 4 admin admin      91 Dec  1 11:18 opencv_extra
drwxr-xr-x. 2 admin admin      53 Dec  3 08:41 Pictures
drwxr-xr-x. 2 admin admin       6 Nov 30 09:33 Public
lrwxrwxrwx. 1 admin admin       6 Dec  9 12:19 sikuli -> Sikuli
drwxrwxrwx. 6 admin admin     112 Dec 10 08:24 Sikuli
-rw-rw-r--. 1 admin admin 4476928 Dec  2 13:42 sikuli_install
drwxrwxr-x. 2 admin admin     123 Dec  3 06:13 Sikuli.sikuli
drwxr-xr-x. 2 admin admin       6 Nov 30 09:33 Templates
-rw-rw-r--. 1 admin admin    2570 Dec 10 08:22 typescript
drwxr-xr-x. 2 admin admin       6 Nov 30 09:33 Videos

[admin@RFC1918 ~]$ cd sikuli

[admin@RFC1918 sikuli]$ echo $PATH
/usr/admin/Sikuli:/usr/bin/java:/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin:/home/admin/.local/bin:/home/admin/bin

[admin@RFC1918 sikuli]$ echo $CLASSPATH
/usr/admin/Sikuli:/usr/bin/java:/usr/admin/Sikuli:/usr/bin/java:/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin:/home/admin/.local/bin:/home/admin/bin

[admin@RFC1918 sikuli]$ ls -l
total 178244

drwxrwxr-x. 2 admin admin      146 Dec 10 05:15 dak2.sikuli
drwxrwxrwx. 7 admin admin      194 Dec 10 04:46 scripts
-rw-rw-r--. 1 admin admin 89065892 Nov 30 10:05 sikulixapi.jar
-rw-rw-r--. 1 admin admin 93451308 Nov 30 10:06 sikulix.jar
drwxrwxr-x. 4 admin admin       79 Dec  6 05:09 testing
drwxrwxr-x. 3 admin admin       49 Dec  7 15:27 testing1

[admin@RFC1918 sikuli]$ cd dak2.sikuli

[admin@RFC1918 dak2.sikuli]$ ls
13m1543841075949.png  13m1543841152578.png 13m1543841459086.png  13m1543841761188.png  13m1543846611451.png  dak2.py

[admin@RFC1918 dak2.sikuli]$ cat dak2.py
import  org.sikuli.script.SikulixForJython
from sikuli import *
Region(434,334,6,4)
"""
click("1543841075949.png")
"""
click("1543841459086.png")
wait(2)
type("clear \n")
wait(2)
type("pwd \n")
wait(1)
type("ls \n")
wait(2)
type ("cd jdk-10.0.2 \n")
wait(2)
type ("ls -l \n")
wait(2)
type ("cd .. \n")
wait(2)
click("1543841761188.png")
wait(2)
click("1543846611451.png")
"""
   wait(2)
   waitVanish(image")
   type("t", KeyModifier.CTRL
   App.open("blah")
   keyDown("a")
   keyUp("a")
   keyDown(Key.Left)
   keyUp(Key.Left)
   rightClick()
   waitVanish()
"""
[admin@RFC1918 dak2.sikuli]$

[admin@RFC1918 dak2.sikuli]$ which java
/usr/bin/java

[admin@RFC1918 dak2.sikuli]$ which jython
/usr/local/bin/jython

[admin@RFC1918 dak2.sikuli]$ jython dak2.py
Traceback (innermost last):
File "dak2.py", line 1, in ?
ImportError: no module named sikuli

[admin@RFC1918 dak2.sikuli]$

      From: RaiMan <email address hidden>
 To: <email address hidden>
 Sent: Monday, December 10, 2018 9:46 AM
 Subject: Re: [Question #676645]: ImportError: no module named sikuli

Your question #676645 on Sikuli changed:
https://answers.launchpad.net/sikuli/+question/676645

    Status: Open => Needs information

RaiMan requested more information:
please paste your relevant environment settings for Jython and Java.

How do you run the script exactly?
is the Jython/bin on path?

Again: why do you do that? why don't you use the features of SikuliX?

--
To answer this request for more information, you can either reply to
this email or enter your reply at the following page:
https://answers.launchpad.net/sikuli/+question/676645

You received this question notification because you asked the question.

RaiMan (raimund-hocke) said : #7

[admin@RFC1918 sikuli]$ echo $CLASSPATH
/usr/admin/Sikuli:/usr/bin/java:/usr/admin/Sikuli:/usr/bin/java:/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin:/home/admin/.local/bin:/home/admin/bin

This is surely not a classpath, that makes sense.

... and sikulixapi.jar is not part of it.

a Java classpath is a list jar-files and/or folders contain java class-files.

Can you help with this problem?

Provide an answer of your own, or ask Dave Kane for more information if necessary.

To post a message you must log in.