how to use exe(use pyinstaller output)in sikuli

Asked by wu

i have the py and i want to use this in my sikuli so i use pyinstaller to output the exe and use app open(exe) or os.system(exe)

but my py include the txt path to do something when i use the exe in sikuli(1.1.4) and the sikuli will tell me can't find the txt。

EX: test.py
  k = open('XXX.txt')
for i in k:
    print(i)

and in sikuli:
  os.system('path.test.exe') or app.open('path.test.ext')

PS: the txt alaways toghter with the test.py

 i use the sys.path[0] the sikuli will jump to sikuil's now path

have some anwser to fixed this?

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
RaiMan (raimund-hocke) said :
#1

I have no idea what you are talking about:
test.py - pyinstaller - exe

Where is the text file with the exe?

Revision history for this message
wu (chouhua) said :
#2

simple: i have a test.py the content is open a 123.txt and use the 123.txt content to do something。
like:
     a = open('123.txt')
     for i in a:
         print(i)
and i use pyinstaller to package the test.py to test.exe。

then my sikuli code will use App.open('test.exe') or os.system('test.exe')

but will tell me can't not find the 123.txt but the 123.txt will put in the folder with test.exe

begin i guess maybe is the test.exe path error so i change write use 【a = open(sys.path[0]+'\123.txt'】the sys.path[0] will print now

the exe path and can find the 123.txt. but use in sikuli will jump to the temp folder, so i have no idea to solve the question

Revision history for this message
Manfred Hampl (m-hampl) said :
#3

Is the 123.txt file packaged inside the test.exe application, or is this a file on the hard disk of the target computer?

Have you tried providing the full path of this file, e.g. something like a = open("C:\\users\\wu\\myfiles\\123.txt")

Revision history for this message
wu (chouhua) said :
#4

Yes

the 123.txt is on the hard disk of the target computer but not packaged inside the test.exe,just give test.exe the txt path。
and the 123.txt 、test.exeis put togather in the folder

and another i already tried providing the full path . just like you write

a = open("C:\\users\\wu\\myfiles\\123.txt")

Revision history for this message
Manfred Hampl (m-hampl) said :
#5

What happens if you execute test.exe outside sikuli, just from a command window?

General remark:
Whenever you get an error message, please provide the full text, not just a short note like "and the sikuli will tell me can't find the txt"

Revision history for this message
wu (chouhua) said :
#6

OK will File test.py, line6 in<module>
FileNotFoundError: [Errno2] no such file or directory:'123.txt'
[5912] Failed to execute script test

that is use sikuli and error log in cmd

Revision history for this message
Manfred Hampl (m-hampl) said :
#7

If you get this error message when executing test.exe in a cmd window, then this is not an error message from Sikuli, but an error message from test.exe.

Your test.exe has a problem, that it cannot find 123.txt.

You have to correct your test.py script and create a new test.exe program which works and does not give an error.

Revision history for this message
wu (chouhua) said :
#8

@Manfred Hampl this error is when i use sikuli to ues the test.exe will get , simple use test.exe in cmd is work good ,but in sikuli will not work and get i tell you the error .

Revision history for this message
Manfred Hampl (m-hampl) said :
#9

What is the current contents of test.py, especially with respect to the file name and its path?

Revision history for this message
wu (chouhua) said :
#10

@Manfred Hampl the test.py
a = open('123.txt')
for i in a:
     print(i)

Revision history for this message
Manfred Hampl (m-hampl) said :
#11

Try the following:

Open a command line window,
change directory to a different directory than the one with test.exe,
and then execute …path…\text.exe (with the correct path given).

What do you get?

Revision history for this message
wu (chouhua) said :
#12

@Manfred Hampl

i got like sikuli to get

Traceback (most recent call last):
  File "test.py", line 6, in <module>
FileNotFoundError: [Errno 2] No such file or directory: '123.txt'
[13360] Failed to execute script test

Revision history for this message
Manfred Hampl (m-hampl) said :
#13

That is what I meant.

The error message does not come from Sikuli, but is coming from test.exe (or test.py).

I suggest that you provide the full path to the 123.txt file in the open() statement in test.py.

a = open('c:\\whatever_the_path_is\\123.txt')
for i in a:
     print(i)

This should then work outside and inside Sikuli.

Can you help with this problem?

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

To post a message you must log in.