Python module subprocess: IndexError: index out of range: 0

Asked by Matthew Israelsohn

A colleague & I have been very happily writing and refining Sikuli tests on Windows 7 Professional x32 with JRE 1.6.0_22-b04 and storing the tests in git via http://plan.io/ which is a web based project management tool.

Today, none of the Sikuli scripts will work via Sikuli X-1.0rc2 on my laptop, but they all work fine on my colleague's laptop.

As far as I am aware, no changes whatsoever have been made to anything on my laptop inbetween the script last working yesterday & it now failing to work today. I have uninstalled Sikuli, rebooted, reinstalled Sikuli, rebooted, sitill no joy. I also can't currently find anything relevant about the below error message on Google and am pretty new to Python etc.

The full contents of the Message window is below:

[info] Sikuli vision engine loaded.
[info] Windows utilities loaded.
[info] VDictProxy loaded.
[error] Stopped
[error] An error occurs at line 4
[error] Error message: Traceback (most recent call last):
File "C:\Users\misraels\AppData\Local\Temp\sikuli-tmp8300701221322966912.py", line 4, in import subprocess
File "C:\Program Files\Sikuli X\sikuli-script.jar\Lib\subprocess.py", line 642, in
File "C:\Program Files\Sikuli X\sikuli-script.jar\Lib\subprocess.py", line 640, in _setup_platform
File "C:\Program Files\Sikuli X\sikuli-script.jar\Lib\warnings.py", line 56, in warn
File "C:\Program Files\Sikuli X\sikuli-script.jar\Lib\warnings.py", line 56, in warn
IndexError: index out of range: 0

Help! This is really frustrating :-(

Question information

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

importing the python module subprocess seems to make problems with the Sikuli builtin Jython 2.5.1.

either use the threading features instead of subprocess or try the workaround of this bug 702155

Revision history for this message
Matthew Israelsohn (misraelsohn) said :
#2

Thanks for very fast response, RaiMan. I don't know how to "use the threading features instead of subprocess" so I tried the workaround of bug 702155 but it still gives the same error:

This is what I did:

1) Copied sikuli-ide.jar to c:\
2) Changed sikuli-IDE.bat to:

@echo off

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="c:\sikuli-script.jar/" -jar "%~d0%~p0sikuli-ide.jar" %*

When I run sikuli-ide.bat the IDE loads. When I try to run the script which works on my colleague's laptop, Sikuli still gives the same error messages as before I did the fix:

[info] Sikuli vision engine loaded.
[info] Windows utilities loaded.
[info] VDictProxy loaded.
[error] Stopped [error] An error occurs at line 4
[error] Error message: Traceback (most recent call last):
File "C:\Users\misraels\AppData\Local\Temp\sikuli-tmp1524787162347353077.py", line 4, in import subprocess
File "C:\Program Files\Sikuli X\sikuli-script.jar\Lib\subprocess.py", line 642, in
File "C:\Program Files\Sikuli X\sikuli-script.jar\Lib\subprocess.py", line 640, in _setup_platform
File "C:\Program Files\Sikuli X\sikuli-script.jar\Lib\warnings.py", line 56, in warn
File "C:\Program Files\Sikuli X\sikuli-script.jar\Lib\warnings.py", line 56, in warn IndexError: index out of range: 0

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

Sorry, seams you were too fast ;-)

I corrected the workaround in bug 702155 that it reads now:

--- 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)

... since it is sikuli-script.jar, that has to be copied.

Revision history for this message
Matthew Israelsohn (misraelsohn) said :
#4

Thanks, but it still doesn't work :-(

(1) I've confirmed sikuli-script.jar is now in c:\
(2) The batch file remains as it is in my above post.
(3) For some reason, the line in the Message window about Firefox has an extra " irefox.exe" which isn't in the code snippet below which allows me to define different possible locations for FF:

   #Likely locations of Firefox on Windows (32/64), Mac, and Linux
   firefoxSearchPaths=[
       "C:\Users\misraels\AppData\Local\Mozilla Firefox\firefox.exe"
   ]

Here's the complete output from the Message window:

Searching C:\Users\misraels\AppData\Local\Mozilla Firefox
  irefox.exe
[error] Stopped
[error] An error occurs at line 60
[error] Error message: Traceback (most recent call last): File "C:\Users\misraels\AppData\Local\Temp\sikuli-tmp7566408192434169889.py", line 60, in
openFirefox("http://www.google.com") #Open a new tab & go to google
File "C:\Users\misraels\AppData\Local\Temp\sikuli-tmp7566408192434169889.py", line 54, in openFirefox
raise "Could not find FireFox! Add your location to the search paths."
File "C:\Program Files\Sikuli X\sikuli-script.jar\Lib\warnings.py", line 56, in warn
File "C:\Program Files\Sikuli X\sikuli-script.jar\Lib\warnings.py", line 56, in warn
IndexError: index out of range: 0

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

at least the import subprocess error has vanished.

the current error should vanish if you use the r"" raw string notation (or the single quoting character ' ) if you do not want to double the backslashes in the "" strings.

 firefoxSearchPaths=[
       r"C:\Users\misraels\AppData\Local\Mozilla Firefox\firefox.exe"
   ]

normally in "" strings you have to double backslashes. but if you don't do it, it works as long as the combination \x does not mean anything, but \n, \r˛ \b˛ \f and some more mean something, so they are converted to the corresponding single (not readable) character.

Revision history for this message
Matthew Israelsohn (misraelsohn) said :
#6

Thanks RaiMan, that solved my question.

Revision history for this message
Govardhan Gunnala (gunnalag) said :
#7

Has there been a fix for this issue?

I am stuck up with the same error as detailed below:

Code:
import sys
import time
import subprocess
import os

Error:
[info] Sikuli vision engine loaded. [info] Windows utilities loaded.
[info] VDictProxy loaded.
[error] Stopped [error] An error occurs at line 3 [error] Error message: Traceback (most recent call last): File "C:\Users\GOVARD~1\AppData\Local\Temp\sikuli-tmp6393242728040316401.py", line 3, in import subprocess File "C:\Program Files\Sikuli X\sikuli-script.jar\Lib\subprocess.py", line 642, in File "C:\Program Files\Sikuli X\sikuli-script.jar\Lib\subprocess.py", line 640, in _setup_platform File "C:\Program Files\Sikuli X\sikuli-script.jar\Lib\warnings.py", line 56, in warn File "C:\Program Files\Sikuli X\sikuli-script.jar\Lib\warnings.py", line 56, in warn IndexError: index out of range: 0

I've tried all the steps detailed in bug 702155 but in vain. can someone help me with a practical soultion this error?

Revision history for this message
Govardhan Gunnala (gunnalag) said :
#8

BTW, I am using the latest version of Sikuli X-1.0rc2 on 32bit Windows7 PC. Also, I see "C:\Program Files\Sikuli X\libs" entry existing in the system path.

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

@ Govardhan:

I am sorry, but I cannot reproduce the error situation with my Win7 installation.

But you say you made the steps from bug 702155 and it still tries to import from
"C:\Program Files\Sikuli X\sikuli-script.jar\Lib\subprocess.py"
which causes the error (the blank at "Sikuli X" is the problem)

I suppose, you have copied sikuli-script.jar to a place whose path does not contain any blanks.

So try the following on command line. I suppose here, a copy of sikuli-script.jar is in C:\

java -Xms64M -Xmx512M -Dfile.encoding=UTF-8 -Dpython.path="C:\sikuli-script.jar/Lib" -jar "C:\Program Files\Sikuli X\sikuli-ide.jar"

the IDE should start up and import subprocess should work.

Revision history for this message
Govardhan Gunnala (gunnalag) said :
#10

Steps did again:

C:\>dir sikuli*
 Directory of C:\

12/23/2010 08:27 AM 17,655,669 sikuli-script.jar

C:\>type "C:\Program Files\Sikuli X\Sikuli-IDE.bat"
@echo off

java -Xms64M -Xmx512M -Dfile.encoding=UTF-8 -Dpython.path="C:\sikuli-script.jar/Lib" -jar "C:\Program Files\Sikuli X\sikuli-ide.jar"

C:\>

Still, the out is same:

[info] Sikuli vision engine loaded. [info] Windows utilities loaded.
[info] VDictProxy loaded.
[error] Stopped [error] An error occurs at line 3 [error] Error message: Traceback (most recent call last): File "C:\Users\GOVARD~1\AppData\Local\Temp\sikuli-tmp935816017363362978.py", line 3, in import subprocess File "C:\Program Files\Sikuli X\sikuli-script.jar\Lib\subprocess.py", line 642, in File "C:\Program Files\Sikuli X\sikuli-script.jar\Lib\subprocess.py", line 640, in _setup_platform File "C:\Program Files\Sikuli X\sikuli-script.jar\Lib\warnings.py", line 56, in warn File "C:\Program Files\Sikuli X\sikuli-script.jar\Lib\warnings.py", line 56, in warn IndexError: index out of range: 0

Yes it's still trying to load from the C:\Program Files\Sikuli X\sikuli-script.jar\, where else should this be modified?

Revision history for this message
Govardhan Gunnala (gunnalag) said :
#11

I event attempted to install it to a top level folder so that there will be not be any of this space issue in the file paths, but stilll no go,

C:\>dir Sikuli\ /w
 Directory of C:\Sikuli

[.] [..] commons-cli-1.2.jar forms-1.2.1.jar ide-icon.ico jintellitype-1.3.6.jar json_simple-1.1.jar
junit-3.8.1.jar [libs] mac_widgets.jar Sikuli IDE.lnk Sikuli-IDE-w.bat Sikuli-IDE.bat Sikuli-IDE.exe
Sikuli-IDE.ini sikuli-ide.jar sikuli-script.jar swing-layout-1.0.1.jar swingx-core-1.6.2.jar
              16 File(s) 20,674,512 bytes
               3 Dir(s) 78,683,459,584 bytes free

C:\>

Any better thoughts?

Revision history for this message
Govardhan Gunnala (gunnalag) said :
#12

BTW, this time it's failing to load modules from "C:\Sikuli\sikuli-script.jar\Lib\" path which doesn't have any spaces in it. So the actual import processes is failing for some reason.

[info] Windows utilities loaded.
[info] VDictProxy loaded.
[error] Stopped [error] An error occurs at line 3 [error] Error message: Traceback (most recent call last): File "C:\Users\GOVARD~1\AppData\Local\Temp\sikuli-tmp5378980481224860484.py", line 3, in import subprocess File "C:\Sikuli\sikuli-script.jar\Lib\subprocess.py", line 642, in File "C:\Sikuli\sikuli-script.jar\Lib\subprocess.py", line 640, in _setup_platform File "C:\Sikuli\sikuli-script.jar\Lib\warnings.py", line 56, in warn File "C:\Sikuli\sikuli-script.jar\Lib\warnings.py", line 56, in warn IndexError: index out of range: 0

can you check the line numbers 642, 640 in C:\Sikuli\sikuli-script.jar\Lib\subprocess.py file?

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

Good idea, but have you changed the Sikuli path entry accordingly (though this has nothing to do with this problem)?

Your situation:

I had a look into the python library code.

- the initial subprocess problem seems to have vanished with the relocation of Sikuli

- now you have another strange situation: since subprocess.py is not able to identify the executable on your system (e.g. cmd.exe) it tries to post a warning and in the respective warning.py, the problem is an empty sys.argv[] (currently this is the case, when running in the IDE), which is not checked there and sys.arrv[0] produces the IndexError: index out of range: 0.

- but this warning should never be produced, because the respective entry should be found in the subprocess.py
I had a look on my Win7 32 with what they try:

import os
print os._os_map.get(os._name)

which prints for me:
[['Windows'], [['C:\\Windows\\system32\\cmd.exe', '/c'], ['command.com', '/c']]]

subprocess tries to spawn these and takes the first that works. In your case there is no working entry.

Suggestion:

Open Sikuli IDE and just run these 2 statements:

import os
print os._os_map.get(os._name)

the output should look like mine above.

Revision history for this message
Govardhan Gunnala (gunnalag) said :
#14

that works fine on my system.

[info] Sikuli vision engine loaded.
[info] Windows utilities loaded.
[info] VDictProxy loaded.
[['Windows'], [['cmd.exe', '/c'], ['command.com', '/c']]]

also my code runs fine if I comment the "import subprocess" statement. It's just failing with/at this statement. What you think can be the specific issue with this module.

BTW, thanks for your quick responses and detailed technical instructions.

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

--- also my code runs fine if I comment the "import subprocess" statement.

LOL, sorry. first, this is clear, since the import subprocess makes the problem. second, then why are you needing to import subprocess if you do not use any of its features - or do you want to use it?

--- But we do not have the same:
I have: ['C:\\Windows\\system32\\cmd.exe', '/c']
You have: ['cmd.exe', '/c']

The BigByte might know why.

So if this should work, C:\Windows\system32 has to be on system path. Just check it to be sure.

Only a question, do not blame me for asking;-)
Did you make any changes in the lower part (should read like SystemVariables) of the extended System Properties? A normal User should only make changes in the upper part, that is specific for the user.

Revision history for this message
Govardhan Gunnala (gunnalag) said :
#16

hmm.. I haven't made any changes w.r.t cmd's location and in fact it's residing under C:\Windows\system32 folder. Surprising is why Sikuli got just cmd.exe :(

C:\>which cmd.exe
/cygdrive/c/Windows/system32/cmd.exe

C:\>

Revision history for this message
Govardhan Gunnala (gunnalag) said :
#17

BTW, I need import subprocess as my automation uses some of it's functions. To get that working, I am still hangging onto this issue. Without this module some of the automation doesn't run. I commented out this module and relevant code to test out the rest of the code works and that did.

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

I understand your need, ok.

It seems you have activated some cygwin environment, which might cause the problem. So did you check your system path (say set on command line)?

can you start up your system without cygwin and try?

BTW: this is not a Sikuli problem, it is a Jython problem and finally a Python problem.

--- If you have some Python available, you might check "import subprocess" in an interactive Python session.

--- Or you might use on commandline:

java -jar c:\Sikuli\sikuli-script.jar -i

which gives you an interactive Jython session, try import subprocess here.

--- Or you might install Jython 2.5.2 standalone and run your scripts from command line. If you want to use this, come back, it is tricky.

Revision history for this message
Govardhan Gunnala (gunnalag) said :
#19

> BTW: this is not a Sikuli problem, it is a Jython problem and finally a Python problem.

This clue was sure enough for me to get my issue fixed. I am happy to see we got this resolved, below are the details.

Cause for the trouble:

I've two Python's installed on my PC (one comes with Cygwin and other one is windows Python). Unfortunately, it's the Cygwin python that was in the path and it expects the files to be passed in a different notation. That caused Sikuli to fail.

Fix:

Removed the Cygwin Python from my path, re-installed Windows Python and Sikuli. That's all Sikuli on my PC started it's performance!!!

Thank you for all the support RaiMan.