import fails

Asked by Torsten Spindler

I'm using rc3 on Windows 7. I followed the documentation at
http://sikuli.org/docx/globals.html#importing-other-sikuli-scripts-reuse-code-and-images
and had some success with it, but it stopped working and I'm trying to figure out why.

I have a simple 3 step sikuli script that opens a menu. I want to reuse this script, if possible. The location is d:\sikuli\openmenu.sikuli

from sikuli import *

click("1349796451457.png")
hover("ycrlage.png")
hover("Neu.png")

The main script is located in d:\sikuli\abnahme00-reset.sikuli:

from sikuli import *
myScriptPath = "d:\\sikuli\\"
if not myScriptPath in sys.path: sys.path.append(myScriptPath)

import openmenu

click("SprachEditor.png")
...

For some reason the code in openmenu is never executed when abnahme00-reset is run. It worked before, though. It stopped working after I tried to place the three steps in openmenu into a function 'doOpenMenu' and call that, as I need to use this code more often. Since this attempt, it fails completely.

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
Best RaiMan (raimund-hocke) said :
#1

ok, this is basic Python knowledge:

when importing a module:
- all code, that would be executed, if this module would be run standalone, is executed once at import time
- the name of the module is registered in the current name space
- using from foobar import * will also register all names of the modules namespace into the current namespace, so the names inside module can be used directly as name without the need for foobar.name

usually, a module does not contain any code, that can be executed at import time (exception: some initialization stuff and/or module global variables). A module mainly contains classes (class():) and functions (def():).

So in your case:

# openmenu.sikuli
from sikuli import *

def function1():
    click("1349796451457.png")
    hover("ycrlage.png")
    hover("Neu.png")

# main script
myScriptPath = r"d:\sikuli"
if not myScriptPath in sys.path: sys.path.append(myScriptPath)
import openmenu

openmenu.function1()
click("SprachEditor.png")

or
# main script with from openmenu import *
myScriptPath = r"d:\sikuli"
if not myScriptPath in sys.path: sys.path.append(myScriptPath)
from openmenu import *

function1()
click("SprachEditor.png")

One more thing:
In your situation all scripts seem to be in the same folder.
If you plan to leave it this way: no need to add sys.path.
Sikuli import finds scripts in the same directory as the main script automagically.

# main script with from openmenu import *
from openmenu import *

function1()
click("SprachEditor.png")

Revision history for this message
Torsten Spindler (tspindler) said :
#2

Thanks for your reply RaiMan, but I cannot test your recommendation right now. It looks like I now face a different problem. I worked with sikuli all morning long and wrote a couple of tests for the GUI. Now, after restarting, I get this error in the log. This is rc3 on Windows 7 64 bit.

[error] Abgebrochen
[error] Ein Fehler in Zeile 1
[error] Fehlermeldung: Traceback (most recent call last):
File "", line 1, in
File "C:\Program Files (x86)\Sikuli X\sikuli-script.jar\Lib\sikuli\__init__.py", line 3, in
File "C:\Program Files (x86)\Sikuli X\sikuli-script.jar\Lib\sikuli\Sikuli.py", line 22, in
java.lang.NoClassDefFoundError: Could not initialize class org.sikuli.script.Finder
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at org.python.core.Py.loadAndInitClass(Py.java:895)
at org.python.core.Py.findClassInternal(Py.java:830)
at org.python.core.Py.findClassEx(Py.java:881)
at org.python.core.packagecache.SysPackageManager.findClass(SysPackageManager.java:133)
at org.python.core.packagecache.PackageManager.findClass(PackageManager.java:28)
at org.python.core.packagecache.SysPackageManager.findClass(SysPackageManager.java:122)
at org.python.core.PyJavaPackage.__findattr_ex__(PyJavaPacka

ge.java:137)
at org.python.core.PyObject.__findattr__(PyObject.java:863)
at org.python.core.imp.import_name(imp.java:849)
at org.python.core.imp.importName(imp.java:884)
at org.python.core.ImportFunction.__call__(__builtin__.java:1220)
at org.python.core.PyObject.__call__(PyObject.java:357)
at org.python.core.__builtin__.__import__(__builtin__.java:1173)
at org.python.core.imp.importFromAs(imp.java:978)
at org.python.core.imp.importFrom(imp.java:954)
at sikuli.Sikuli$py.f$0(C:\Program Files (x86)\Sikuli X\sikuli-script.jar\Lib\sikuli\Sikuli.py:211)
at sikuli.Sikuli$py.call_function(C:\Program Files (x86)\Sikuli X\sikuli-script.jar\Lib\sikuli\Sikuli.py)
at org.python.core.PyTableCode.call(PyTableCode.java:165)
at org.python.core.PyCode.call(PyCode.java:18)
at org.python.core.imp.createFromCode(imp.java:386)
at org.python.core.util.importer.importer_load_module(importer.java:109)
at org.python.modules.zipimport.zipimporter.zipimporter_load_module(zipimporter.java:161

)
at org.python.modules.zipimport.zipimporter$zipimporter_load_module_exposer.__call__(Unknown Source)
at org.python.core.PyBuiltinMethodNarrow.__call__(PyBuiltinMethodNarrow.java:47)
at org.python.core.imp.loadFromLoader(imp.java:513)
at org.python.core.imp.find_module(imp.java:467)
at org.python.core.PyModule.impAttr(PyModule.java:100)
at org.python.core.imp.import_next(imp.java:715)
at org.python.core.imp.import_name(imp.java:824)
at org.python.core.imp.importName(imp.java:884)
at org.python.core.ImportFunction.__call__(__builtin__.java:1220)
at org.python.core.PyObject.__call__(PyObject.java:357)
at org.python.core.__builtin__.__import__(__builtin__.java:1173)
at org.python.core.imp.importAll(imp.java:998)
at sikuli$py.f$0(C:\Program Files (x86)\Sikuli X\sikuli-script.jar\Lib\sikuli\__init__.py:3)
at sikuli$py.call_function(C:\Program Files (x86)\Sikuli X\sikuli-script.jar\Lib\sikuli\__init__.py)
at org.python.core.PyTableCode.call(PyTableCode.java:165)
at o

rg.python.core.PyCode.call(PyCode.java:18)
at org.python.core.imp.createFromCode(imp.java:386)
at org.python.core.util.importer.importer_load_module(importer.java:109)
at org.python.modules.zipimport.zipimporter.zipimporter_load_module(zipimporter.java:161)
at org.python.modules.zipimport.zipimporter$zipimporter_load_module_exposer.__call__(Unknown Source)
at org.python.core.PyBuiltinMethodNarrow.__call__(PyBuiltinMethodNarrow.java:47)
at org.python.core.imp.loadFromLoader(imp.java:513)
at org.python.core.imp.find_module(imp.java:467)
at org.python.core.imp.import_next(imp.java:713)
at org.python.core.imp.import_name(imp.java:824)
at org.python.core.imp.importName(imp.java:884)
at org.python.core.ImportFunction.__call__(__builtin__.java:1220)
at org.python.core.PyObject.__call__(PyObject.java:357)
at org.python.core.__builtin__.__import__(__builtin__.java:1173)
at org.python.core.imp.importAll(imp.java:998)
at org.python.pycode._pyx25.f$0(:1)
at org.pyth

on.pycode._pyx25.call_function()
at org.python.core.PyTableCode.call(PyTableCode.java:165)
at org.python.core.PyCode.call(PyCode.java:18)
at org.python.core.Py.runCode(Py.java:1261)
at org.python.core.Py.exec(Py.java:1305)
at org.python.util.PythonInterpreter.exec(PythonInterpreter.java:206)
at org.sikuli.script.ScriptRunner.runPython(ScriptRunner.java:61)
at org.sikuli.ide.SikuliIDE$ButtonRun.runPython(SikuliIDE.java:1572)
at org.sikuli.ide.SikuliIDE$ButtonRun$1.run(SikuliIDE.java:1677)

java.lang.NoClassDefFoundError: java.lang.NoClassDefFoundError: Could not initialize class org.sikuli.script.Finder

Revision history for this message
Torsten Spindler (tspindler) said :
#3

After a restart. this error comes up now when trying to run a script:

java.lang.UnsatisfiedLinkError: java.lang.UnsatisfiedLinkError: C:\Program Files (x86)\Sikuli X\libs\VisionProxy.dll: Can't load IA 32-bit .dll on a AMD 64-bit platform

Revision history for this message
Torsten Spindler (tspindler) said :
#4

I installed sikuli and the app on a 32 bit Win7 vm and your recommendation works now, as well as leaving the sys.path alone as the two scripts reside in the same directory. I suspect that my earlier problems with the import might also come from win7 64 bit integration problems of sikuli?

Revision history for this message
Torsten Spindler (tspindler) said :
#5

Thanks RaiMan, that solved my question.

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

Sikuli works on 64-Bit Windows, as stated on the homepage:
- use a 32-Bit Java 6
- use Sikuli-IDE.bat to star the IDE

You import problems have nothing to do with that.
It was as I tried to explain basic Python stuff in comment #1

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

Sikuli works on 64-Bit Windows, as stated on the homepage:
- use a 32-Bit Java 6
- use Sikuli-IDE.bat to star the IDE

You import problems have nothing to do with that.
It was as I tried to explain basic Python stuff in comment #1