path wrong when doing import in a skl file

Asked by randescr

Hello

I'm following the document to import .sikuli file
there are 2 files:

one is import.sikuli, code is:
import os

myPath = os.path.dirname(getBundlePath())
if not myPath in sys.path: sys.path.append(myPath)

import myLib

popup(myLib.getStr())

and anotner one is myLib.sikuli, the code:
from sikuli.Sikuli import *

def getStr():
 return "string in myLib"

it works fine when I open the IDE and running it
and then I export the import.sikuli as import.skl, put it in the same folder to myLib.sikuli
but the import.skl is not running as expected
a error message was shown:
File "/var/folders/0R/0RZYxv8AEvKtC7Ln-CBw6++++T1/-Tmp-/tmp--180056268.sikuli/import.sikuli/import.py", line 6, in <module>
import myLib
ImportError: No module named myLib

then, I put one line before import myLib in import.sikuli:
popup(getBundlePath())

export it as .skl, then run it, I see the path is wrong, the popup window shows:
/var/folders/0R/0RZYxv8AEvKtC7Ln-CBw6++++T1/-Tmp-/tmp--180056268.sikuli/import.sikuli

how could I fix it ?

Question information

Language:
English Edit question
Status:
Answered
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
RaiMan (raimund-hocke) said :
#1

since a .skl is a zipped version of the script folder, it is unzipped to a temp folder to run it.

getBundlePath() reflects the situation at runtime, so it is the temp folder in case of a .skl.

The only solution currently: run it as a .sikuli from commandline using the -r option.

If you want to run it as .skl (which makes no sense in your case, since the imported stuff must be a .sikuli (no .skl supported)), you have to give the current working directory as a parameter to the script.

Can you help with this problem?

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

To post a message you must log in.