can't import modules

Asked by Jose Pablo Jimenez Velez

I have followed the instructions in the documentation but no matter what I do I can't import a custom module

Currently I have a folder with 2 sikuli scripts
libBroser.sikuli
test.sikuli

libBrowser has in the first line: from sikuli import * and two methods

my test.sikuli file only has "import libBrowser"

At this poing I want to clarify that I'm running mac Lion, both files are in the same folder, I have tried adding the path to the sys.path, I have all the alternatives that I found to add the folder to the path.
Also I tested the path doing popup(str(sys.path)) in the script, the path does have the correct info, I even see the libBrowser in the path.

But every time I try to run the script I get this:

[error] Stopped
[error] An error occurs at line 8
[error] Error message:
Traceback (most recent call last):
 File "/var/folders/df/lwy_y8g15t921z7kmzq5cxqm0000gn/T/sikuli-tmp7184138209776326037.py", line 8, in
 import libBrowser
 File "/Applications/Sikuli-IDE.app/Contents/Resources/Java/sikuli-script.jar/Lib/sikuli/SikuliImporter.py", line 45, in load_module
 File "/Applications/Sikuli-IDE.app/Contents/Resources/Java/sikuli-script.jar/Lib/sikuli/SikuliImporter.py", line 25, in _load_module
ImportError: No module named libBrowser

Any ideas? am I missing something?

Question information

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

This works on my Mac Lion:

- both scripts.sikuli are in same folder (then no sys.path entry is needed)
- main.sikuli opened and run in Sikuli-IDE

# main.sikuli
import sub
sub.test()

#sub.sikuli
from sikuli import *
def test():
    popup("hello from sub")

BTW: sys.path has to contain the parent folder, where the to-be-imported.sikuli is located.

You might have a filename problem: the libBrowser.sikuli does not contain a libBrowser.py or vice versa, because you renamed the xxx.sikuli in the finder !?

Revision history for this message
Jose Pablo Jimenez Velez (jpjimenezv) said :
#2

Excellent! thanks for the quick response!

That was the problem, I did rename the file and I was not aware that there was an internal dependency.
I opened the file in sikuli IDE and did a "Save as" with the new name and it worked just fine.

This might be worth to have in the docs :P

Thanks again!

Revision history for this message
Jose Pablo Jimenez Velez (jpjimenezv) said :
#3

Excellent! thanks for the quick response!

That was the problem, I did rename the file and I was not aware that there
was an internal dependency.
I opened the file in sikuli IDE and did a "Save as" with the new name and
it worked just fine.

This might be worth to have in the docs :P

Thanks again!

On Mon, Dec 5, 2011 at 10:05 AM, RaiMan <
<email address hidden>> wrote:

> Your question #180960 on Sikuli changed:
> https://answers.launchpad.net/sikuli/+question/180960
>
> Status: Open => Answered
>
> RaiMan proposed the following answer:
> This works on my Mac Lion:
>
> - both scripts.sikuli are in same folder (then no sys.path entry is needed)
> - main.sikuli opened and run in Sikuli-IDE
>
> # main.sikuli
> import sub
> sub.test()
>
> #sub.sikuli
> from sikuli import *
> def test():
> popup("hello from sub")
>
> BTW: sys.path has to contain the parent folder, where the to-be-
> imported.sikuli is located.
>
> You might have a filename problem: the libBrowser.sikuli does not
> contain a libBrowser.py or vice versa, because you renamed the
> xxx.sikuli in the finder !?
>
> --
> 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/180960/+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/180960
>
> You received this question notification because you asked the question.
>

--
José Pablo Jiménez V

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

always welcome.

--- This might be worth to have in the docs :P

Right! I will add some words about that to the relevant chapter. Thanks