10.2: ImportError with other script in same folder --- sys.path has to contain each script folder, that you want to import
Hi,
I read several thread from the forum, as well as Sikili's guide and no way to import a Sikuli module.
I'm on WinXP.
All files are in C:\Program Files\Sikuli
main.sikuli :
import VPsLogin
type("m", KEY_WIN)
doubleClick( imgpath)
VPsLogin.sub1()
....
VPsLogin.sikuli :
from sikuli import *
def sub1(self):
....
I got the error message :
"[sikuli] Error message:
Traceback (most recent call last):
File "C:\DOCUME~
import VPsLogin
ImportError: No module named VPsLogin"
If someone has an idea, I try a lots of things from the forum and it is always the same result.
Fabian
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
|
#1 |
might be, that this is because C:\Program Files\ needs special access rights and it is not writeable for everyone.
When importing a some_name.py file from some_name.sikuli in Jython (means Sikuli IDE), Jython writes a some_name$py.class file to that directory. this write operation might make problems deep down inside and comes to the surface as "No module ..." error.
So I suggest to put your files in a directory, that you have full access to (e.g. C:\Sikuli_Modules\ ) and put your .sikuli stuff there.
Revision history for this message
|
#2 |
I moved my two Sikuli's scripts in C:\NonReg to avoid this kind of issue but it's not working.
I get the same message :
"[sikuli] Error message:
Traceback (most recent call last):
File "C:\DOCUME~
import VPsLogin
ImportError: No module named VPsLogin"
I tested also with 'from VPsLogin import *' and 'import VPsLogin' but always the same error
Revision history for this message
|
#3 |
I've added at the top main.sikuli these lines :
myScriptPath=
if not myScriptPath in sys.path: sys.path.
And now it works fine !
Thanks for your help RainMan
Revision history for this message
|
#4 |
---1. If the main script and the imported scripts (all as .sikuli) are in the same folder and running the main script, the import should find the stuff to import.
So if you have:
# c:\NonReg\
import sub
and
# c:\NonReg\
from sikuli import *
running main in Sikuli IDE should give no error
---2. sys.path
In sys.path you need only the folder that contains the .sikuli scripts and not the scripts itself.
your case:
myScriptPath=
if not myScriptPath in sys.path: sys.path.
Revision history for this message
|
#5 |
In my case it doesn't work.
I tested :
# c:\NonReg\
myScriptPath=
if not myScriptPath in sys.path: sys.path.
import sub
# c:\NonReg\
from sikuli import *
and I have always the same issue "ImportError: No module named VPsLogin"
It's working only if I have :
# c:\NonReg\
myScriptPath=
if not myScriptPath in sys.path: sys.path.
import sub
# c:\NonReg\
from sikuli.Sikuli import *
That's really weird but if I'm able to work in this way, it doesn't matter for me
Revision history for this message
|
#6 |
Please, do me a favor and run the following test script after saving it to the c:\NonReg folder as main.sikuli:
print "***** before import"
for e in sys.path: print e
okImport = False
try:
import subNotExists
okImport = True
except:
print "***** after import not ok"
for e in sys.path: print e
if okImport:
print "***** after import ok"
for e in sys.path: print e
Revision history for this message
|
#7 |
... and paste the content of the message area here, please.
Revision history for this message
|
#8 |
Here are the content of the message area :
"***** before import
C:\Program Files\Sikuli\
C:\Program Files\Sikuli\Lib
C:\Program Files\Sikuli\
__classpath__
__pyclasspath__/
C:\NonReg\
***** after import not ok
C:\Program Files\Sikuli\
C:\Program Files\Sikuli\Lib
C:\Program Files\Sikuli\
__classpath__
__pyclasspath__/
C:\NonReg\
Revision history for this message
|
#9 |
I moved sikuli-script.jar in C:\NonReg and also trying to modify Environment Variables but I have always this outcome :
ScreenMatchProxy loaded.
VDictProxy loaded.
Win32Util loaded.
ScreenMatchProxy loaded.
***** before import
C:\Program Files\Sikuli\
C:\Program Files\Sikuli\Lib
C:\Program Files\Sikuli\
__classpath__
__pyclasspath__/
***** after import not ok
C:\Program Files\Sikuli\
C:\Program Files\Sikuli\Lib
C:\Program Files\Sikuli\
__classpath__
__pyclasspath__/
Revision history for this message
|
#10 |
I just realized, that I never asked:
What version of Sikuli are you using?
Does not seem to be the latest version or even rc3?
Revision history for this message
|
#12 |
Uuuups, I already doubted that ;-)
10.2 does not have the import support for .sikuli scripts, that is only available in X-1.0rc3.
In 10.2 you have to do it as you found out already.
Any reason for using 10.2 instead of X?
X is much faster and has more features.
Revision history for this message
|
#13 |
One more thing:
10.2 import does not make available the images, that are captured in the imported scripts.
All images have either be referenced with absolute path or be in the main script (where bundlePath points to)
Revision history for this message
|
#14 |
OK RaiMan.
So I install Sikuli X rc3 (https:/
So now, my first test with main and sub in C:\Program Files\Sikuli
#main.sikuli:
print "***** before import"
for e in sys.path: print e
okImport = False
try:
import subNotExists
okImport = True
except:
print "***** after import not ok"
for e in sys.path: print e
if okImport:
print "***** after import ok"
for e in sys.path: print e
#sub.sikuli
from sikuli import *
In message area, I got :
"
[error] Stopped
[error] An error occurs at line 1
[error] Error message: Traceback (most recent call last):
File "", line 1, in
File "C:\Program Files\Sikuli\
File "C:\Program Files\Sikuli\
java.lang.
at java.lang.
at java.lang.
at org.python.
at org.python.
at org.python.
at org.python.
at org.python.
at org.python.
at org.python.
at
org.python.
at org.python.
at org.python.
at org.python.
at org.python.
at org.python.
at org.python.
at org.python.
at sikuli.
at sikuli.
at org.python.
at org.python.
at org.python.
at org.python.
at org.python.
at org.python.
t.zipimporter$
at org.python.
at org.python.
at org.python.
at org.python.
at org.python.
at org.python.
at org.python.
at org.python.
at org.python.
at org.python.
at org.python.
at sikuli$
at sikuli$
at org.python.
at org.python.
at or
g.python.
at org.python.
at org.python.
at org.python.
at org.python.
at org.python.
at org.python.
at org.python.
at org.python.
at org.python.
at org.python.
at org.python.
at org.python.
at org.python.
at org.python.
at org.python.
at org.
python.
at org.python.
at org.python.
at org.python.
at org.python.
at org.sikuli.
at org.sikuli.
at org.sikuli.
java.lang.
Revision history for this message
|
#15 |
I made a brand new install of Sikuli X and all exceptions are gone.
main.sikuli and sub.sikuli are in the same folder (c:\NonReg)
So I ran the main.sikuli :
print "***** before import"
for e in sys.path: print e
okImport = False
try:
import subNotExists
okImport = True
except:
print "***** after import not ok"
for e in sys.path: print e
if okImport:
print "***** after import ok"
for e in sys.path: print e
Here is my message area :
"
***** before import
C:\Program Files\Sikuli X\sikuli-script.jar
C:\Program Files\Sikuli X\Lib
C:\Program Files\Sikuli X\sikuli-
__classpath__
__pyclasspath__/
C:/DOCUME~
C:\DOCUME~
C:/Program Files/Sikuli/
C:\Program Files\Sikuli
.
C:/NonReg/
C:\NonReg
***** after import not ok
C:\Program Files\Sikuli X\sikuli-script.jar
C:\Program Files\Sikuli X\Lib
C:\Program Files\Sikuli X\sikuli-
__classpath__
__pyclasspath__/
C:/DOCUME~
C:\DOCUME~
C:/Program Files/Sikuli/
C:\Program Files\Sikuli
.
C:/NonReg/
C:\NonReg"
Revision history for this message
|
#16 |
I made a new test with the x release :
main.sikuli :
myScriptPath=
if not myScriptPath in sys.path:
import VPsLogin
VPsLogin.sub1()
....
VPsLogin.sikuli :
from sikuli import *
def sub1(self):
....
And it works !!
So it was clearly a release issue.
Thanks a lot for your time and your help RaiMan !!!
Revision history for this message
|
#17 |
BTW: def sub1(self):
does not make sense if you do not have self defined classes with methods.
So it should be:
def sub1():
So this should give you a runtime error in main like:
sub1 needs 1 parameter 0 given
Revision history for this message
|
#18 |
Indeed, it's just a copy/paste issue ;)