X 1.0rc1: Windows: import Jython module subprocess not possible - workaround

Bug #702155 reported by surfdork on 2011-01-12
12
This bug affects 2 people
Affects Status Importance Assigned to Milestone
Sikuli
Medium
RaiMan

Bug Description

*** If you face problems like the one below (standard python modules cannot be imported) try this workaround:

--- copy sikuli-script.jar from the Sikuli X program folder to e.g. c:\ (or another place were the resulting absolute path does not contain any blanks)

and modify the .bat in the Sikuli X program folder:

--- remove the PATH= statement, it is not needed, you have it (to be checked!) already in your system path ;-)

--- set the python.path option to: -Dpython.path="c:\sikuli-script.jar/"
the changed line should read (based on the distributed version, sikuli-script.jar copied to c:\):
%JAVA_EXE% -Xms64M -Xmx512M -Dfile.encoding=UTF-8 -Dpython.path="c:\sikuli-script.jar/" -jar "%~d0%~p0sikuli-ide.jar" %*

run this .bat to start the IDE, and you hopefully find, that your imports work.

Comment for NetBeans (and Eclipse) users:
If you are using the Python plugin configured with Jython 2.5.1, you will not have this problems.

Background: Jython 2.5.1 seems to have problems with some import handling of/in python modules/packages contained in .jar files whose absolute path contains blanks.

-----------------------
The following code worked perfectly in Sikuli 10, within the IDE and in Netbeans on all Windows operating systems. Now it fails globally. Any code invoking subprocess fails on all windows operating systems, repeat ALL Windows operating systems. This failure occurs on user systems where the .jar files are not changed, unpacked nor run from NetBeans.

import glob
import os
import subprocess

setShowActions(True)
dirname = "Z:\BUILDS\Daily_BUILDS\QA_MainBranch_Install\*.install"
setBundlePath("C:\\SikuliTest\\ImageLibrary\\96dpi\\SignIn\\")
filespec = "setup.exe"
instlpath = glob.glob (os.path.join (dirname, filespec))
subprocess.call (instlpath[0] + ' /S /z" ')
if exists("SignIn_Launch.png", 300):
    popup("Install Successful")
    exit()

Error:
[debug] close all ScreenHighlighter
[info] Stopped
[info] An error occurs at line 3
[info] Error message:
Traceback (most recent call last):
  File "C:\Users\MIKEAD~1.OVE\AppData\Local\Temp\sikuli-tmp6953702407610701410.py", line 3, in <module>
    import subprocess
  File "C:\Program Files (x86)\Sikuli X\sikuli-script.jar\Lib\subprocess.py", line 642, in <module>
  File "C:\Program Files (x86)\Sikuli X\sikuli-script.jar\Lib\subprocess.py", line 640, in _setup_platform
  File "C:\Program Files (x86)\Sikuli X\sikuli-script.jar\Lib\warnings.py", line 56, in warn
  File "C:\Program Files (x86)\Sikuli X\sikuli-script.jar\Lib\warnings.py", line 56, in warn
IndexError: index out of range: 0

RaiMan (raimund-hocke) wrote :

Windows 7 confirmed:
simply "import subprocess" in Sikuli- X IDE brings the above error.

This works for me: running a Sikuli script in NetBeans using the Jython 2.5.1, that comes with the PyDev plugin.

Seems to be "some whatever" in the Sikuli X scriptrunner context together with the packaged Jython

RaiMan (raimund-hocke) wrote :

I somewhere read about that Jython in some environments has problems with filenames containing blanks:

so just give it a try: put sikuli-script.jar in a directory without any blanks.

RaiMan (raimund-hocke) wrote :

I guess, this key modifier is still missing. You should post a bug.

Since the mouse pointer should be on the item, what about rightClick(Env.getMouseLocation()).

RaiMan (raimund-hocke) wrote :

sorry other question ;-)

RaiMan (raimund-hocke) on 2011-01-13
summary: - Sikuli can't import subprocess, all scripts using subprocess are broken
+ X 1.0rc1: Windows: import Jython module subprocess not possible

copy sikuli-ide.jar to e.g. c:\

and modify the .bat in the Sikuli X program folder:

--- remove the PATH= statement, it is not needed, you have it (to be checked!) already in your system path

--- set the python.path option to: -Dpython.path="c.\sikuli-script.jar/"

run this .bat to start the IDE, and you will find, that your import subprocess works.

summary: - X 1.0rc1: Windows: import Jython module subprocess not possible
+ X 1.0rc1: Windows: import Jython module subprocess not possible -
+ workaround
RaiMan (raimund-hocke) wrote :

should read:
--- set the python.path option to: -Dpython.path="c:\sikuli-script.jar/"

description: updated
RaiMan (raimund-hocke) on 2011-01-13
description: updated
surfdork (surfdork) wrote :
Download full text (4.9 KiB)

Fails,

I changed the bat to
@echo off
-Dpython.path="c:\sikuli-script.jar/"
set JAVA_EXE="java"
if defined PROGRAMFILES(X86) set JAVA_EXE="%PROGRAMFILES(X86)%\Java\jre6\bin\java.exe"
%JAVA_EXE% -Xms64M -Xmx512M -Dfile.encoding=UTF-8 -Dpython.path="%~d0%~p0sikuli-script.jar/" -jar "%~d0%~p0sikuli-ide.jar" %*

as per your instructions

@echo off
-Dpython.path="c:\sikuli-script.jar/"
PATH=%PATH%;%~d0%~p0libs
set JAVA_EXE="java"
if defined PROGRAMFILES(X86) set JAVA_EXE="%PROGRAMFILES(X86)%\Java\jre6\bin\java.exe"
%JAVA_EXE% -Xms64M -Xmx512M -Dfile.encoding=UTF-8 -Dpython.path="%~d0%~p0sikuli-script.jar/" -jar "%~d0%~p0sikuli-ide.jar" %*

Fails as well in that errors are returned when launching from the bat, errors are returned when launching sikuli

'-Dpython.path' is not recognized as an internal or external command,
operable program or batch file.
[info] locale: en_US
[debug] init user preferences
Redirect stdout/stderr to console.

[debug] close all ScreenHighlighter
[info] Stopped
[info] An error occurs at line 1
[info] Error message:
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "C:\Program Files\Sikuli X\sikuli-script.jar\Lib\sikuli\Sikuli.py", line 23, in <module>
java.lang.NoClassDefFoundError: Could not initialize class org.sikuli.script.App

The following is expected

 at java.lang.Class.forName0(Native Method)

 at java.lang.Class.forName(Unknown Source)

 at org.python.core.SyspathJavaLoader.loadClass(SyspathJavaLoader.java:107)

 at java.lang.ClassLoader.loadClass(Unknown Source)

 at org.python.core.Py.findClassEx(Py.java:817)

 at org.python.core.packagecache.SysPackageManager.findClass(SysPackageManager.java:133)

 at org.python.core.packagecache.PackageManager.findClass(PackageManager.java:28)

 at org.python.core.packagecache.SysPackageManager.findClass(SysPackageManager.java:122)

 at org.python.core.PyJavaPackage.__findattr_ex__(PyJavaPackage.java:137)

 at org.python.core.PyObject.__findattr__(PyObject.java:869)

 at org.python.core.imp.import_name(imp.java:771)

 at org.python.core.imp.importName(imp.java:806)

 at org.python.core.ImportFunction.__call__(__builtin__.java:1232)

 at org.python.core.PyObject.__call__(PyObject.java:367)

 at org.python.core.__builtin__.__import__(__builtin__.java:1202)

 at org.python.core.imp.importFromAs(imp.java:884)

 at org.python.core.imp.importFrom(imp.java:860)

 at sikuli.Sikuli$py.f$0(C:\Program Files\Sikuli X\sikuli-script.jar\Lib\sikuli\Sikuli.py:183)

 at sikuli.Sikuli$py.call_function(C:\Program Files\Sikuli X\sikuli-script.jar\Lib\sikuli\Sikuli.py)

 at org.python.core.PyTableCode.call(PyTableCode.java:165)

 at org.python.core.PyCode.call(PyCode.java:18)

 at org.python.core.imp.createFromCode(imp.java:326)

 at org.python.core.util.importer.importer_load_module(importer.java:109)

 at org.python.modules.zipimport.zipimporter.zipimporter_load_module(zipimporter.java:161)

 at org.python.modules.zipimport.zipimporter$zipimporter_load_module_exposer.__call__(Unknown Source)

 at org.python.core.PyBuiltinMethodNarrow.__call__(PyBuiltinMethodNarrow.java:47)

...

Read more...

RaiMan (raimund-hocke) wrote :

@surfdork

sorry, for not being not enough. Sometimes even much is not enough ;-)

the python.path option has to be modified in the line, where java is called, so the line looks like:

%JAVA_EXE% -Xms64M -Xmx512M -Dfile.encoding=UTF-8 -Dpython.path="c:\sikuli-script.jar/" -jar "%~d0%~p0sikuli-ide.jar" %*

I have changed the instructions accordingly.

Anyway, good luck and all the best.

description: updated
RaiMan (raimund-hocke) on 2011-03-23
description: updated
RaiMan (raimund-hocke) on 2013-02-22
Changed in sikuli:
status: New → In Progress
importance: Undecided → Medium
assignee: nobody → RaiMan (raimund-hocke)
tags: added: jython
To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers