pyinstaller subprocess do not find the file

1,488 views
Skip to first unread message

Jean Manu

unread,
May 21, 2012, 2:27:40 PM5/21/12
to PyInstaller
Hi there,

I have a little issue when I try to compile my work.
I have tried with pyinstaller1.5 and 1.6.
I use python 2.7

I make a very simple test with subprocess to try it!

test.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import subprocess, sys

print sys.path[0]+"\\test2.py"

f = open(sys.path[0]+"\\test2.py", 'r')
print f.read()
f.close()

subprocess.Popen([ "python", sys.path[0]+"\\test2.py"])

###

test2.py
#!/usr/bin/env python
# -*- coding: utf-8 -*
message = "\n\rYour message sent at %s to %s has been received by the
recipient.\n\r" % ('123456', '123456')
print message

So after pyinstaller has create an executable file on windows, I run
it and I got this:
Traceback (most recent call last):
File "<string>", line 14, in <module>
File "E:\pyinstaller\test\build\pyi.win32\test\out01-PYZ.pyz
\subprocess", line 679, in __init__
File "E:\pyinstaller\test\build\pyi.win32\test\out01-PYZ.pyz
\subprocess", line 896, in _execute_child
WindowsError: [Error 2] Fichier introuvable
RC: -1 from test
OK.
Deactivating activation context
Releasing activation context
Done

I have also tried to include the specified file (test2.py) on the spec
file, or to copy the test2.py on my dist directory.
Has you can see on my first script I print the test2.py, because it
say that the file is not found ! but it print my file ? so I don't
understand where is the issue, the subprocess doesn't work with
pyinstaller ??
Could you please help me?

Thank you for your help.

Hartmut Goebel

unread,
May 22, 2012, 10:21:27 AM5/22/12
to pyins...@googlegroups.com
Am 21.05.2012 20:27, schrieb Jean Manu:
I have tried with pyinstaller1.5 and 1.6.

Please use the current development version. It makes accessing files easier, using sys._meipass. See <http://groups.google.com/group/pyinstaller/browse_thread/thread/8964aeb8a16adb64/bd206d7f0bf80b66?lnk=gst&q=sys._meipass#bd206d7f0bf80b66> for more.


print sys.path[0]+"\\test2.py"

This is uggly code. You should train to use os.path.join.

I have also tried to include the specified file (test2.py) on the spec
file, or to copy the test2.py on my dist directory.

There are two separate topics: a) Binging data-files to the dist-directory and b) bringing python-scripts to the dist-directory.

You need to put something like this into your .spec file:

a = Analysis(['test1.py'])
b= Analysis(['tes21.py'])

pyzA = PYZ(a.pure)
exeA = EXE(pyzA,
          a.scripts,
          a.binaries,
          a.zipfiles,
          a.datas,
          a.dependencies,
          name=os.path.join('dist', 'test2.exe'),
          debug=False,
          strip=False,
          upx=True,
          console=1 )

pyzB = PYZ(b.pure)
exeB = EXE(pyzB,
          b.scripts,
          b.binaries,
          b.zipfiles,
          b.datas,
          b.dependencies,
          name=os.path.join('dist', 'test2.exe'),
    ....)

coll = COLLECT(exeA, exeB,
               a.binaries,
               a.zipfiles,
               a.datas,
               b.binaries,
               b.zipfiles,
               b.datas,
    ...)

This makes test2 a separete, forzen executable. In test1 you are running it with:
subprocess.Popen([ os.path.join(sys._meipass, "test2..exe"])


--
Schönen Gruß
Hartmut Goebel
Dipl.-Informatiker (univ), CISSP, CSSLP

Goebel Consult
http://www.goebel-consult.de

Monatliche Kolumne: http://www.cissp-gefluester.de/2012-04-compliance-bringt-keine-sicherheit
Blog: http://www.goebel-consult.de/blog/prefering-git-over-mercurial

Goebel Consult ist Mitglied bei http://www.7-it.de/

Reply all
Reply to author
Forward
0 new messages