[1.1.0] Windows: My imports stopped working when I moved to newest version (sys.path issue?)

Asked by forrest

Sorry if this has been answered, but I have looked and cannot find an answer for recent builds.

My imports worked all along until I upgraded to the most recent version.

Running windows7pro.
Referencing the SetupLog.txt, I can see that my last (working) version was "SikuliX Package Build: 1.1.0 2014-12-17_01:01nightly"
My current (problem) install shows "Setup: 1.1.0 2015-04-18_01:00nightly"

My development directories look like:

c:/projects/bin/sikuli/projectX.sikuli/
c:/projects/bin/sikuli/projectY.sikuli/
c:/projects/bin/sl/settings.py

Note "sl" in the same dir as "sikuli".
PYTHONPATH is C:\projects\bin

The scripts for projectX I developed with the last version of the IDE allowed me to:
from sikuli import *
import os, sys
import sl.settings as settings
...etc...

However, when I run the IDE, I now get...
[error] ImportError ( No module named sl )

I have tried to launch the IDE with
C:\usrbin\sikulix\runsikulix.cmd -Dpython.path=C:/projects/bin

Still, the same error.
The only thing that seems to work is

import org.sikuli.basics.SikulixForJython
from sikuli import *
import os, sys
sys.path.append(r'c:\projects\bin') # <-- THIS allows import to succeed
import sl.settings as settings

Putting a static path in all my scripts is really not an option -- that is what the sl.settings file is for!

So, how do I get that sys.path functionality back?

That is, how can I either
1) Structure my files so that imports work for free -- like before
--or--
2) I can provide path info on the runsikulix.cmd command line

Thank You
forrest

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
皇甫春峰 (xpnsau) said :
#1

Hi forrest:
    I've met the same problem with sikuli, I've add my xxx.py in the same path with sikuli.
If you import sikuli successfully, there will be some stdout in command-line.
C:\Users\huangc11\Desktop\sikuliJython>jython temp.py
[info] Windows utilities loaded.
[info] Sikuli vision engine loaded.
[info] Text Recognizer inited.
[info] VDictProxy loaded.

Thanks,
Huangfu

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

Thanks Huangfu, but what you say is related to earlier versions of Sikuli.

What forrest asks is related to late versions of SikuliX version 1.1.0, where indeed some things have changed internally, that might lead to different behaviour (which would be a bug).

I just tested on a Win7-64 with Java 7 and the latest build from today:
- a PYTHONPATH in environment is not recognised (according to the rules: for Jython (Sikuli) use JYTHONPATH)
- -Dpython.path=something is recognised and gets entry[0] in sys.path

there is another question where I currently try to sort out and support all options available for Jython to get something on sys.path (either forefront or at runTime):
https://bugs.launchpad.net/sikuli/+bug/1312239

Revision history for this message
forrest (fjohnston) said :
#3

Thank you both for the timely response.
Perhaps I am missing something but I don't see an answer that works in either of the posts.

Given development directories that look like:

    c:/sl/bin/sikuli/ListBox.sikuli/
    c:/sl/bin/sl/settings.py

SikuliX install is at
   C:\usrbin\sikulix

Here is the first 4 lines of my program in ListBox.sikuli

    import org.sikuli.basics.SikulixForJython
    from sikuli import *
    import os, sys
    for sp in sys.path: print sp

When I run the IDE, it prints the paths but PYTHONPATH nor any jython.path nor python.path is ever printed.

IDE Messages
    C:\sl\bin\sikuli\ListBox.sikuli
    C:\usrbin\sikulix\Lib
    C:\usrbin\sikulix\sikulix.jar\Lib
    __classpath__
    __pyclasspath__/
    [error] script [ ListBox ] stopped with error in line 7
    [error] ImportError ( No module named sl )

Here is what I see (edited) in the Windows Command Console
Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation. All rights reserved.
c:\Users\m\workspace>echo %PYTHONPATH%
C:\sl\bin
c:\Users\m\workspace>java -version
java version "1.7.0_71"
...etc...
c:\Users\m\workspace>C:\usrbin\sikulix\runsikulix.cmd -Djython.path=C:/sl/bin
...etc...
Java(TM) SE Runtime Environment (build 1.7.0_71-b14)
...etc...
+++ using: -Xms64M -Xmx512M -Dfile.encoding=UTF-8 -Dsikuli.FromCommandLine -jar C:\usrbin\sikulix\sikulix.jar -Djython.path=C:/sl/bin

[ Same result IDE Messages ]

c:\Users\m\workspace>C:\usrbin\sikulix\runsikulix.cmd -Dpython.path=C:/sl/bin
...etc...
Java(TM) SE Runtime Environment (build 1.7.0_71-b14)
...etc...
+++ using: -Xms64M -Xmx512M -Dfile.encoding=UTF-8 -Dsikuli.FromCommandLine -jar C:\usrbin\sikulix\sikulix.jar -Dpython.path=C:/sl/bin

[ Same result IDE Messages ]

Here is everything I have tried after reading the posts...
c:\Users\m\workspace>doskey /h
java -version
set PYTHONPATH=C:\sl\bin
C:\usrbin\sikulix\runsikulix.cmd -Djython.path=C:/sl/bin
C:\usrbin\sikulix\runsikulix.cmd -Djython.path=C:\sl\bin
C:\usrbin\sikulix\runsikulix.cmd -Dpython.path=C:/sl/bin
C:\usrbin\sikulix\runsikulix.cmd -Dpython.path=C:\sl\bin
set PYTHONPATH=C:\sl\bin;
C:\usrbin\sikulix\runsikulix.cmd
C:\usrbin\sikulix\runsikulix.cmd -Djython.path=C:\sl\bin
C:\usrbin\sikulix\runsikulix.cmd -Dpython.path=C:\sl\bin
C:\usrbin\sikulix\runsikulix.cmd --Dpython.path=C:\sl\bin
C:\usrbin\sikulix\runsikulix.cmd --Djython.path=C:\sl\bin
doskey /h

What am I missing here?

Thanks,
forrest

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

as mentioned in comment #2:
with Jython use JYTHONPATH instead of PYTHONPATH, since per convention PYTHONPATH is not recognised by Jython, to avoid clashes on systems having both Python and Jython.

... and to have the relevant info from the related bug also here:

current state for version 1.1.0:
- PYTHONPATH is ignored
- JYTHONPATH is used if specified and overwrites -Dpython.path which is used if present

still to finally check, but should work
- .pth files should be recognised as well (if in JYTHONPATH/site-packages or other folders according to the rules)

in any case:
import org.sikuli.script.SikulixForJython
(or deprecated: import org.sikuli.basics.SikulixForJython)
takes care, that sikulixapi.jar/Lib gets sys.path[0]

Revision history for this message
forrest (fjohnston) said :
#5

IF I set JYTHONPATH then I cannot even get the IDE or the interactive jython to start - both have same error
NameError: name 'SIKULIX_IS_WORKING' is not defined

I have tried
c:\Users\m\workspace>set JYTHONPATH=c:\sl\bin
c:\Users\m\workspace>set JYTHONPATH=c:\sl\bin;
c:\Users\m\workspace>set JYTHONPATH=c:/sl/bin;
c:\Users\m\workspace>set JYTHONPATH=c:/sl/bin
with the same result:

c:\Users\m\workspace>C:\usrbin\sikulix\runsikulix.cmd
+++ running this Java
java version "1.7.0_71"
Java(TM) SE Runtime Environment (build 1.7.0_71-b14)
Java HotSpot(TM) 64-Bit Server VM (build 24.71-b01, mixed mode)
+++ trying to run SikuliX
+++ using: -Xms64M -Xmx512M -Dfile.encoding=UTF-8 -Dsikuli.FromCommandLine -jar C:\usrbin\sikulix\sikulix.jar
[info] HotkeyManager: add Capture Hotkey: CTRL+SHIFT 2 (50, 3)
[info] HotkeyManager: add Abort Hotkey: ALT+SHIFT C (67, 9)
[error] RunTimeIDE: *** terminating: JythonScriptRunner: cannot be initialized:
Traceback (most recent call last):
  File "<string>", line 1, in <module>
NameError: name 'SIKULIX_IS_WORKING' is not defined

c:\Users\m\workspace>java -jar %SIKULI_HOME%\sikulix.jar -i
[error] RunTimeIDE: *** terminating: JythonScriptRunner: cannot be initialized:
Traceback (most recent call last):
  File "<string>", line 1, in <module>
NameError: name 'SIKULIX_IS_WORKING' is not defined

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

could please use

C:\usrbin\sikulix\runsikulix.cmd -d 3 -c

so the startup debug is shown and every output goes to the command line window.

... and with java.exe

java -Dsikuli.Debug=3 -jar %SIKULI_HOME%\sikulix.jar -i

the reason for this crash (I will fix the behaviour to tell exactly what happens here) is the fact, that an internally issued
from sikuli import *

did not work apparently

C:\usrbin\sikulix\runsikulix.jar/Lib

should be on sys.path at this time (supposing your %SIKULI_HOME% points to C:\usrbin\sikulix), but apparently is not or in a way, that it cannot be used for import.

Are you using some stuff like citrix or other unix based stuff, that remap folders?

Revision history for this message
forrest (fjohnston) said :
#7

Re: "...could you please..." #6

==========================
Fresh Win Command Console
==========================
Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation. All rights reserved.

c:\Users\m\workspace>set j
JAVA_HOME=C:\usrbin\jdk17u71_64
JDK15=C:\usrbin\jdk15022
JDK16=C:\usrbin\jdk16u24
JDK17=C:\usrbin\jdk17u71_64
JDK18=C:\usrbin\jdk18u25_64

c:\Users\m\workspace>set JYTHONPATH=c:\sl\bin

c:\Users\m\workspace>C:\usrbin\sikulix\runsikulix.cmd -d 3 -c
+++ running this Java
java version "1.7.0_71"
Java(TM) SE Runtime Environment (build 1.7.0_71-b14)
Java HotSpot(TM) 64-Bit Server VM (build 24.71-b01, mixed mode)
+++ trying to run SikuliX
+++ using: -Xms64M -Xmx512M -Dfile.encoding=UTF-8 -Dsikuli.FromCommandLine -jar C:\usrbin\sikulix\sikulix.ja
r -d 3 -c
[debug] RunTimeINIT: loadOptions: check: c:\Users\m\workspace
[debug] RunTimeINIT: loadOptions: check: C:\Users\m
[debug] RunTimeINIT: loadOptions: check: C:\Users\m\AppData\Roaming\Sikulix\SikulixStore
[debug] RunTimeINIT: global init: entering as: IDE
[debug] RunTimeINIT: ScreenDevice 0 contains (0,0) --- will be used as primary
[debug] RunTimeINIT: fSxBase: C:\usrbin\sikulix
[debug] RunTimeINIT: runs as sikulix.jar in: C:\usrbin\sikulix
[debug] RunTimeINIT: exists libs folder at: C:\Users\m\AppData\Roaming\Sikulix\SikulixLibs_201504180100
[debug] RunTimeINIT: addToWindowsSystemPath: added to systempath:
C:\Users\m\AppData\Roaming\Sikulix\SikulixLibs_201504180100
[debug] RunTimeINIT: checkJavaUsrPath: added to ClassLoader.usrPaths
***** show environment for IDE (build 201504180100)
user.home: C:\Users\m
user.dir (work dir): c:\Users\m\workspace
user.name: m
java.io.tmpdir: C:\Users\m\AppData\Local\Temp
running 64Bit on Windows (6.1) from a jar
java 7-64 version 1.7.0_71-b14 vm 24.71-b01 class 51.0 arch amd64
app data folder: C:\Users\m\AppData\Roaming\Sikulix
libs folder: C:\Users\m\AppData\Roaming\Sikulix\SikulixLibs_201504180100
executing jar: C:\usrbin\sikulix\sikulix.jar
*** classpath dump sikulix
  0: /C:/usrbin/sikulix/sikulix.jar
*** classpath dump end
***** show environment end
[debug] RunTimeIDE: global init: leaving
[debug] RunTimeIDE: initIDEbefore: entering
[debug] RunTimeIDE: initIDEbefore: leaving
[debug] init user preferences
[debug] IDE: running with Locale: en_US
[debug] --- Sikuli parameters ---
[debug] 1: -d
[debug] 2: 3
[debug] 3: -c
[info] HotkeyManager: add Capture Hotkey: CTRL+SHIFT 2 (50, 3)
[debug] HotkeyManager: add Capture Hotkey: CTRL+SHIFT 2 (50, 3)
[info] HotkeyManager: add Abort Hotkey: ALT+SHIFT C (67, 9)
[debug] HotkeyManager: add Abort Hotkey: ALT+SHIFT C (67, 9)
[debug] ScriptingSupport: initScriptingSupport: enter
[debug] JythonSupport: init: starting
[debug] JythonSupport: init: success
[debug] JythonSupport: ***** Jython sys.path
 0: c:\sl\bin
 1: C:\usrbin\sikulix\Lib
 2: C:\usrbin\sikulix\sikulix.jar\Lib
 3: __classpath__
 4: __pyclasspath__/
[debug] JythonSupport: ***** Jython sys.path end
[error] RunTimeIDE: *** terminating: JythonScriptRunner: cannot be initialized:
Traceback (most recent call last):
  File "<string>", line 1, in <module>
NameError: name 'SIKULIX_IS_WORKING' is not defined

[debug] RunTimeIDE: final cleanup
[debug] FileManager: deleteFileOrFolder:
C:\Users\m\AppData\Local\Temp\Sikulix_460738209

c:\Users\m\workspace>
=================================================================
New Win Command Console
=================================================================
Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation. All rights reserved.

c:\Users\m\workspace>set j
JAVA_HOME=C:\usrbin\jdk17u71_64
JDK15=C:\usrbin\jdk15022
JDK16=C:\usrbin\jdk16u24
JDK17=C:\usrbin\jdk17u71_64
JDK18=C:\usrbin\jdk18u25_64

c:\Users\m\workspace>set JYTHONPATH=c:\sl\bin

c:\Users\m\workspace>java -Dsikuli.Debug=3 -jar %SIKULI_HOME%\sikulix.jar -i
[debug] RunTimeINIT: loadOptions: check: c:\Users\m\workspace
[debug] RunTimeINIT: loadOptions: check: C:\Users\m
[debug] RunTimeINIT: loadOptions: check: C:\Users\m\AppData\Roaming\Sikulix\SikulixStore
[debug] RunTimeINIT: global init: entering as: IDE
[debug] RunTimeINIT: ScreenDevice 0 contains (0,0) --- will be used as primary
[debug] RunTimeINIT: fSxBase: C:\usrbin\sikulix
[debug] RunTimeINIT: runs as sikulix.jar in: C:\usrbin\sikulix
[debug] RunTimeINIT: exists libs folder at: C:\Users\m\AppData\Roaming\Sikulix\SikulixLibs_201504180100
[debug] RunTimeINIT: addToWindowsSystemPath: added to systempath:
C:\Users\m\AppData\Roaming\Sikulix\SikulixLibs_201504180100
[debug] RunTimeINIT: checkJavaUsrPath: added to ClassLoader.usrPaths
***** show environment for IDE (build 201504180100)
user.home: C:\Users\m
user.dir (work dir): c:\Users\m\workspace
user.name: m
java.io.tmpdir: C:\Users\m\AppData\Local\Temp
running 64Bit on Windows (6.1) from a jar
java 7-64 version 1.7.0_71-b14 vm 24.71-b01 class 51.0 arch amd64
app data folder: C:\Users\m\AppData\Roaming\Sikulix
libs folder: C:\Users\m\AppData\Roaming\Sikulix\SikulixLibs_201504180100
executing jar: C:\usrbin\sikulix\sikulix.jar
*** classpath dump sikulix
  0: /C:/usrbin/sikulix/sikulix.jar
*** classpath dump end
***** show environment end
[debug] RunTimeIDE: global init: leaving
[debug] RunTimeIDE: initIDEbefore: entering
[debug] RunTimeIDE: initIDEbefore: leaving
[debug] init user preferences
[debug] IDE: running with Locale: en_US
[debug] IDE: Switching to ScriptRunner with option -r, -t or -i
[debug] Runner: commandline:
[debug] --- Sikuli parameters ---
[debug] 1: -i
[debug] ScriptingSupport: initScriptingSupport: enter
[debug] JythonSupport: init: starting
[debug] JythonSupport: init: success
[debug] JythonSupport: ***** Jython sys.path
 0: c:\sl\bin
 1: C:\usrbin\sikulix\Lib
 2: C:\usrbin\sikulix\sikulix.jar\Lib
 3: __classpath__
 4: __pyclasspath__/
[debug] JythonSupport: ***** Jython sys.path end
[error] RunTimeIDE: *** terminating: JythonScriptRunner: cannot be initialized:
Traceback (most recent call last):
  File "<string>", line 1, in <module>
NameError: name 'SIKULIX_IS_WORKING' is not defined

[debug] RunTimeIDE: final cleanup
[debug] FileManager: deleteFileOrFolder:
C:\Users\m\AppData\Local\Temp\Sikulix_1141427870

c:\Users\m\workspace>

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

Thanks. looks like some bug. try to find and fix as soon as possible.

Revision history for this message
forrest (fjohnston) said :
#9

Thank you.

Is there a way that I can know when this gets fixed ?
That is, what should I look for either on the board or release notes, etc ?
Newbie...

Best of Luck,
forrest

-----Original Message-----
From: <email address hidden> [mailto:<email address hidden>] On Behalf Of RaiMan
Sent: Friday, April 24, 2015 12:57 AM
To: Forrest Johnston
Subject: Re: [Question #265660]: [1.1.0] Windows: My imports stopped working when I moved to newest version (sys.path issue?)

Your question #265660 on Sikuli changed:
https://answers.launchpad.net/sikuli/+question/265660

    Status: Open => Answered

RaiMan proposed the following answer:
Thanks. looks like some bug. try to find and fix as soon as possible.

--
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/265660/+confirm?answer_id=7

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/265660

You received this question notification because you asked the question.

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

When I have checked, I will turn this question into a bug.

When it is fixed, the bug is set to fix-committed/critical to show it is available in the respective nightly build.

Of all this you will be notified automatically by launchpad due to your subscription.

I guess late on Monday it is fixed.

Thanks for testing and patience.

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

I tested with your setup.

Does not seem to be some bug (anymore ?) - it simply works with the actual build.

Might be, that it had to do with the Jython version.

I now use 2.7rc3 (which indeed says it has fixed some Windows problems)

I just fired a new build. Should be ready within about 1/2 h.

run setup in a clean folder and run the same test please.

Can you help with this problem?

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

To post a message you must log in.