Issue with Sikuli imports

Asked by Fabian

Hi all,

I read a lots oh thread about Sikuli (as well as the Help file) and I do not succeed in importing module in main Sikuli script.
I'm working with Win XP and all Sikuli's file are in the same directory.
In C:\Program Files\Sikuli, I have :
* main.sikuli
import sub
sub.function()
* sub.sikuli
from sikuli import*
def function():
 print "Hello"

When running main.sikuli, I get the following message :
"[sikuli] Stopped
[sikuli] An error occurs at line 1
[sikuli] Error message:
Traceback (most recent call last):
  File "C:\DOCUME~1\genesys\LOCALS~1\Temp\sikuli-tmp1210157467660887871.py", line 1, in <module>
    import sub
ImportError: No module named sub"

I tried a lots of way to solve this issue with all differents theads about this subject but I'm still stuck.

Thanks

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
Fabian
Solved:
Last query:
Last reply:
Revision history for this message
Roman Podolyan (podolyan-roman) said :
#1

Fabian,

Look at http://pastebin.com/FgrsySsa

I uploaded there 2 excerpts of import code from my working script and module, composed from what I got from answers in this forum.

I hope that will help you to get import working.

Feel free (and anybody else) to ask additional questions if needed.

Revision history for this message
Fabian (fabian-ledoeuff) said :
#2

Thanks Roman for your quick answer !
I try with your examples and I have also this error :
"Traceback (most recent call last):
  File "C:\DOCUME~1\genesys\LOCALS~1\Temp\sikuli-tmp5753347838395976638.py", line 12, in <module>
    from webmoves import *
ImportError: No module named webmoves"

The issue comes from the line "from webmoves import *".
I wonder if it is not due to my OS (winXP)

Revision history for this message
Roman Podolyan (podolyan-roman) said :
#3

:D Captain Obvious says that you should substitute 'webmoves', my module name, with _yours_ module name. Also change paths "/Projects/Sikuli/articles.sikuli/" to the path to the module you want to import (I'd recommend to store modules and scripts in the same folder/path).

Revision history for this message
Fabian (fabian-ledoeuff) said :
#4

Of course I've changed all these parameters Roman :)
I've copied your all snippet to test.

* articles.sikuli
import sys
myLib = "c:\\Program Files\\Sikuli\\articles.sikuli\\"
if not myLib in sys.path:
 sys.path.append(myLib)

# making unit reload under the IDE (workaround)
if 'webmoves' in sys.modules:
         del sys.modules['webmoves']
         webmoves = None
         del webmoves
# importing your unit
from webmoves import *

# import organizing code end

* webmoves.sikuli
import sys
myLib = "c:\\Program Files\\Sikuli\\articles.sikuli\\"
if not myLib in sys.path:
 sys.path.append(myLib)

# making unit reload under the IDE (workaround)
if 'webmoves' in sys.modules:
         del sys.modules['webmoves']
         webmoves = None
         del webmoves
# importing your unit
from webmoves import *

# import organizing code end

These two scripts are in C:\Program Files\Sikuli (in the same folder)

Revision history for this message
Roman Podolyan (podolyan-roman) said :
#5

In my case there is no "webmoves.sukuli", just "webmoves.py" , _Python_module_in the same folder articles.sikuli .

You want to work with two Sikuli folders and not Python, but other Sikuli module?
Is it really necessary, you don't want with Python, but only Sikuli modules?

If so, I'll try to compose a different example later tonight (and, maybe, on my other PC with Win XP), or, maybe, even two examples for the two different settings, and upload them somewhere.

Revision history for this message
Fabian (fabian-ledoeuff) said :
#6

If I keep only webmoves.py (remove the webmoves.sikuli folder) it works !
Thanks for all Roman !