To run python file containing sikuli scripts by double clicking it

Asked by chaitu on 2016-12-30

i wrote sikuli scripts using python in eclipse and it is working fine. i have that .py file in my current directory. How to run that .PY file by double clicking it.

If that .Py file contains normal Python script without any Sikuli features then it is running fine by double clicking by showing output on command prompt.

The problem arises when i run the .Py file which contains sikuli features and sikuli script inside it..code is not running..

can anyone tell me how to run the .py file containing sikuly scripts from workspace by just double cliking it.

thank you.

Question information

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

inside Eclipse you have a setup most probably with PyDev, that is configured correctly with respect to the Jython package and the Java classpath.

Outside Eclipse there are 2 prerequisites you have to take care for:
- have the sikulixapi.jar on Java classpath
- assure, that double clicking a .py file is run by Jython and not by Python, which cannot run SikuliX scripts

may be this helps:
https://github.com/RaiMan/SikuliX-2014/wiki/Jython-in-IDEs-like-Eclipse-or-running-it-from-commandline

chaitu (chaitu123) said : #2

hi Raiman,

still i didn't get the solution to run the .py file by double clicking it. when i double click the .py file containing sikuli scripts just falshing of the screen happening thats it.

i added raw_input() also end of the code still it is showing the same..

can we run .py file containing sikuli scripts just by double clicking from d folder or c folder ??

please help me out
thank you

RaiMan (raimund-hocke) said : #3

without the things mentioned in comment #1 running the .py file outside Eclipse will not work.

Furthermore the aspects of running a Sikuli script from commandline apply (see docs).

... and if using images to find something on the screen, you have to be aware of this:
http://sikulix-2014.readthedocs.io/en/latest/scripting.html#image-search-path-where-sikulix-looks-for-image-files

... and finally it might be needed, to wrap the scriptrun into a command file, that then in turn can be used as double-click target.

chaitu (chaitu123) said : #4

thanks for the reply .

but still i didn't find any solution to this..I set sikulixapi on java classpath.

bu-t u said ........assure, that double clicking a .py file is run by Jython and not by Python, which cannot run SikuliX scripts

i dont know how to do this ..please help me out ??

RaiMan (raimund-hocke) said : #5

You need a Jython installation and then use the jython commandfile and a wrapping commandfile for each script, that then is the doubleclick target.

or do the same with the command:
java -cp <path-to>\sikulixide.jar org.python.util.jython <path-to>\myscript.py

... and wrap this in an appropriate commandfile.

in all cases comment #3 applies.

chaitu (chaitu123) said : #6

java -cp <C:\Users\M1037536\Desktop\sikuli>\sikulix.jar org.python.util.jython <D:\M1037536\Jython1\firstProg>\hema_SFB.py

when i use this command in my command prompt it is showing ACCESS DENIED

RaiMan (raimund-hocke) said : #7

Sorry: the < > in comment #5 are only to show, that the contained text is a placeholder.

chaitu (chaitu123) said : #8

how to make sure that the code should run through jython but not python outside of eclipse ??

chaitu (chaitu123) said : #9

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).

chaitu (chaitu123) said : #10

i tried your solution in comment #7 by removing < > ...then i got the error as

Traceback (most recent call last):
  File "D:\M1037536\Jython1\firstProg\hema_SFB.py", line 13, in <module>
    from Sikuli import *
ImportError: No module named Sikuli

chaitu (chaitu123) said : #11

when i run that command in my cmd ............................ java -jar C:\Users\M1037536\Desktop\sikuli\sikulix.jar calc.sikuli

it is just opening sikuli ide dats it..code is not running

C:\>java -jar C:\Users\M1037536\Desktop\sikuli\sikulix.jar calc.sikuli
Jan 05, 2017 11:58:47 AM java.util.prefs.WindowsPreferences <init>
WARNING: Could not open/create prefs root node Software\JavaSoft\Prefs at root 0x80000002. Windows RegCreateKeyEx(...) returned error code 5.
[info] HotkeyManager: add Capture Hotkey: CTRL+SHIFT 2 (50, 3)
[info] HotkeyManager: add Abort Hotkey: ALT+SHIFT C (67, 9

RaiMan (raimund-hocke) said : #12

at comment #10:

comment #5, #3 and #1 apply.

chaitu (chaitu123) said : #14

hi Raiman the sikuli code is now working fine from command prompt also.

Now i am able to run sikuli python files from both command prompt and eclipse ide. It is done.

My problem is when i double click that python file (Not from command prompt and eclipse ide) it is not running .

please help me out

chaitu (chaitu123) said : #15

hi Raiman the sikuli code is now working fine from command prompt also.

Now i am able to run Sikuli python files from both command prompt and eclipse ide. It is done.

My problem is when i double click that python file (Not from command prompt and eclipse ide) it is not running .

sample code goes like this.

from time import sleep
for i in range(01,10):

    print "welcome to india"
    sleep(1)

import org.sikuli.script.SikulixForJython
from sikuli import *
from sikuli.Sikuli import *
import org.sikuli.script.ImagePath;
ImagePath.setBundlePath("D:\Sikuli_CMD");
s=Screen()
s.click("hema1.png")
 s.wait("hema2.png")
 s.type("skype for business"+Key.ENTER);

it is running from command prompt and eclipse ide.. But i need to run this program just by double clicking on the python file..dats it . Is there any solution please suggest me ..

RaiMan (raimund-hocke) said : #16

As long as double clicking on .py files is connected to the Python interpreter: no chance.

As already mentioned before
- either tell your windows, to run Jython when doubleclicking a .py file
- or wrap a commandfile around your script run, which in turn can then be double clicked

Another method might be, to pack your script into a runnable .jar which in turn will start with the JVM if double clicked
... but this needs some minimum Java programming
some information and conveniences:
http://sikulix-2014.readthedocs.io/en/latest/scenarios.html#prepare-and-use-your-own-jar-files-in-the-jython-environment

chaitu (chaitu123) said : #17

Thank you Raiman .I dont know how to run this

How to tell windows to run .py files by using jython interpreter but not
python ??

On Mon, 9 Jan 2017 at 7:47 PM, RaiMan <email address hidden>
wrote:

> Your question #423503 on Sikuli changed:
>
> https://answers.launchpad.net/sikuli/+question/423503
>
>
>
> Status: Open => Answered
>
>
>
> RaiMan proposed the following answer:
>
> As long as double clicking on .py files is connected to the Python
>
> interpreter: no chance.
>
>
>
> As already mentioned before
>
> - either tell your windows, to run Jython when doubleclicking a .py file
>
> - or wrap a commandfile around your script run, which in turn can then be
> double clicked
>
>
>
> Another method might be, to pack your script into a runnable .jar which in
> turn will start with the JVM if double clicked
>
> ... but this needs some minimum Java programming
>
> some information and conveniences:
>
>
> http://sikulix-2014.readthedocs.io/en/latest/scenarios.html#prepare-and-use-your-own-jar-files-in-the-jython-environment
>
>
>
> --
>
> 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/423503/+confirm?answer_id=15
>
>
>
> 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/423503
>
>
>
> You received this question notification because you asked the question.
>
>

chaitu (chaitu123) said : #18

please tell me how to tell windows to run .py files using jython interpreter ?

How to pack my script into a runnable .jar which in turn will start with the JVM if double clicked ??

please provide step by step so that it will be helpfull to me,..

thank you...Please help me out ?

chaitu (chaitu123) said : #21

this is my sample code..

from time import sleep

for i in range(01,10):
    print "welcome to india"
    sleep(1)

from sikuli import *
import org.sikuli.script.ImagePath;
ImagePath.setBundlePath("D:\Sikuli_CMD");
s=Screen()
s.click("hema1.png")

.........................................it is executing fine from both eclipse and cmd...

but when i double click that python file then it python prompt is opened and it is printing Welcome to india 10 times then it is showing error as

Traceback(most recent call last):

File "D:\M1037536\jython1\firstprog\__init__.py", line 9,in <module>

                 from sikuli import *
Import Error: No module named sikuli

please help me out .

RaiMan (raimund-hocke) said : #22

Since I do not have the time, to guide you further down the road:

- for solutions about "connect .py to Jython" consult the net elsewhere.

- you should check the solution "wrap scriptrun in command files"

... and another possibility:
Since double clicking a .py file leads to processing with C-Python which in turn crashes, you might add a feature to your scripts, that detects this situation and runs the jython scriptrun as a subprocess inside C-Python.
... or simply make a C-Python script for every SikuliX script, that delegates the SikuliX scriptrun to a subprocess and you have your double-clickable-.py

Can you help with this problem?

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

To post a message you must log in.