py2exe deal with python command line inside a program

Discussion in 'Python' started by susan_kijiji@yahoo.ca, Jan 22, 2010.

  1. Guest

    Hi,

    I need to create a python subprogress, like this:
    myProcess = subprocess.Popen([sys.executable, 'C:\myscript.py'],
    env=env, stdin=subprocess.PIPE,
    stdout=subprocess.PIPE)

    sys.executable was printed out as ''C:\\Python25\\python.exe'', how
    can I make this work in executable package through py2exe?

    I have to fix the following problems:
    -Source code shouldn't exposed in an executable program
    -Since python environment is not required when running an executable
    program, how to deal with the situation that "C:\\Python25\
    \python.exe" is required as part of command?

    Thanks in advance!
     
    , Jan 22, 2010
    #1
    1. Advertising

  2. im_smialing Guest

    On Jan 22, 2:35 pm, wrote:
    > Hi,
    >
    > I need to create a python subprogress, like this:
    > myProcess = subprocess.Popen([sys.executable, 'C:\myscript.py'],
    >                                        env=env, stdin=subprocess.PIPE,
    >                                        stdout=subprocess.PIPE)
    >
    > sys.executable was printed out as ''C:\\Python25\\python.exe'', how
    > can I make this work in executable package through py2exe?
    >
    > I have to fix the following problems:
    > -Source code shouldn't exposed in an executable program
    > -Since python  environment is not required when running an executable
    > program, how to deal with the situation that "C:\\Python25\
    > \python.exe" is required as part of command?
    >
    > Thanks in advance!


    Anyone can help? The problem took me two days and still no solutions
     
    im_smialing, Jan 23, 2010
    #2
    1. Advertising

  3. On Jan 22, 7:35 pm, wrote:
    > Hi,
    >
    > I need to create a python subprogress, like this:
    > myProcess = subprocess.Popen([sys.executable, 'C:\myscript.py'],
    >                                        env=env, stdin=subprocess.PIPE,
    >                                        stdout=subprocess.PIPE)
    >
    > sys.executable was printed out as ''C:\\Python25\\python.exe'', how
    > can I make this work in executable package through py2exe?
    >
    > I have to fix the following problems:
    > -Source code shouldn't exposed in an executable program
    > -Since python  environment is not required when running an executable
    > program, how to deal with the situation that "C:\\Python25\
    > \python.exe" is required as part of command?
    >
    > Thanks in advance!


    Hi. What does it do when you try to execute it with py2exe? Does it
    fail to run? What is the error?
     
    Jonathan Hartley, Jan 24, 2010
    #3
  4. Chris Rebert Guest

    On Sun, Jan 24, 2010 at 3:28 AM, Jonathan Hartley <> wrote:
    > On Jan 22, 7:35 pm, wrote:
    >> Hi,
    >>
    >> I need to create a python subprogress, like this:
    >> myProcess = subprocess.Popen([sys.executable, 'C:\myscript.py'],
    >>                                        env=env, stdin=subprocess.PIPE,
    >>                                        stdout=subprocess.PIPE)
    >>
    >> sys.executable was printed out as ''C:\\Python25\\python.exe'', how
    >> can I make this work in executable package through py2exe?
    >>
    >> I have to fix the following problems:
    >> -Source code shouldn't exposed in an executable program
    >> -Since python  environment is not required when running an executable
    >> program, how to deal with the situation that "C:\\Python25\
    >> \python.exe" is required as part of command?
    >>
    >> Thanks in advance!

    >
    > Hi. What does it do when you try to execute it with py2exe? Does it
    > fail to run? What is the error?


    The subprocess call would fail utterly since sys.executable is
    apparently inaccurate for py2exe-generated executables.

    Cheers,
    Chris
    --
    http://blog.rebertia.com
     
    Chris Rebert, Jan 24, 2010
    #4
  5. im_smialing Guest

    Hi Jonathan,

    Here is the traceback I got, 'test.py' is where "main" starts, and I
    replaced 'sys.executable' with string 'python':

    args: ['python', 'C:\\myscript.py']

    Traceback (most recent call last):
    File "test.py", line 22, in <module>
    File "subprocess.pyc", line 594, in __init__
    File "subprocess.pyc", line 816, in _execute_child
    WindowsError: [Error 2] The system cannot find the file specified


    On Jan 24, 6:28 am, Jonathan Hartley <> wrote:
    > On Jan 22, 7:35 pm, wrote:
    >
    >
    >
    >
    >
    > > Hi,

    >
    > > I need to create a python subprogress, like this:
    > > myProcess = subprocess.Popen([sys.executable, 'C:\myscript.py'],
    > >                                        env=env, stdin=subprocess.PIPE,
    > >                                        stdout=subprocess.PIPE)

    >
    > > sys.executable was printed out as ''C:\\Python25\\python.exe'', how
    > > can I make this work in executable package through py2exe?

    >
    > > I have to fix the following problems:
    > > -Source code shouldn't exposed in an executable program
    > > -Since python  environment is not required when running an executable
    > > program, how to deal with the situation that "C:\\Python25\
    > > \python.exe" is required as part of command?

    >
    > > Thanks in advance!

    >
    > Hi. What does it do when you try to execute it with py2exe? Does it
    > fail to run? What is the error?- Hide quoted text -
    >
    > - Show quoted text -
     
    im_smialing, Jan 24, 2010
    #5
  6. im_smialing Guest

    On Jan 24, 6:35 am, Chris Rebert <> wrote:
    > On Sun, Jan 24, 2010 at 3:28 AM, Jonathan Hartley <> wrote:
    > > On Jan 22, 7:35 pm, wrote:
    > >> Hi,

    >
    > >> I need to create a python subprogress, like this:
    > >> myProcess = subprocess.Popen([sys.executable, 'C:\myscript.py'],
    > >>                                        env=env, stdin=subprocess.PIPE,
    > >>                                        stdout=subprocess.PIPE)

    >
    > >> sys.executable was printed out as ''C:\\Python25\\python.exe'', how
    > >> can I make this work in executable package through py2exe?

    >
    > >> I have to fix the following problems:
    > >> -Source code shouldn't exposed in an executable program
    > >> -Since python  environment is not required when running an executable
    > >> program, how to deal with the situation that "C:\\Python25\
    > >> \python.exe" is required as part of command?

    >
    > >> Thanks in advance!

    >
    > > Hi. What does it do when you try to execute it with py2exe? Does it
    > > fail to run? What is the error?

    >

    Thanks for pointing that, this time I try to use 'python' as the arg,
    I got an error:
    WindowsError: [Error 2] The system cannot find the file specified

    Because the subprocess is looking for a source code location, and
    which was hard coded, any suggestion to work out the issue?


    > The subprocess call would fail utterly since sys.executable is
    > apparently inaccurate for py2exe-generated executables.
    >
    > Cheers,
    > Chris
    > --http://blog.rebertia.com- Hide quoted text -
    >
    > - Show quoted text -
     
    im_smialing, Jan 24, 2010
    #6
  7. Chris Rebert Guest

    On Sun, Jan 24, 2010 at 10:25 AM, im_smialing <> wrote:
    > On Jan 24, 6:35 am, Chris Rebert <> wrote:
    >> On Sun, Jan 24, 2010 at 3:28 AM, Jonathan Hartley <> wrote:
    >> > On Jan 22, 7:35 pm, wrote:
    >> >> Hi,

    >>
    >> >> I need to create a python subprogress, like this:
    >> >> myProcess = subprocess.Popen([sys.executable, 'C:\myscript.py'],
    >> >>                                        env=env, stdin=subprocess.PIPE,
    >> >>                                        stdout=subprocess.PIPE)

    >>
    >> >> sys.executable was printed out as ''C:\\Python25\\python.exe'', how
    >> >> can I make this work in executable package through py2exe?

    >>
    >> >> I have to fix the following problems:
    >> >> -Source code shouldn't exposed in an executable program
    >> >> -Since python  environment is not required when running an executable
    >> >> program, how to deal with the situation that "C:\\Python25\
    >> >> \python.exe" is required as part of command?

    >>
    >> >> Thanks in advance!

    >>
    >> > Hi. What does it do when you try to execute it with py2exe? Does it
    >> > fail to run? What is the error?

    >>

    > Thanks for pointing that, this time I try to use 'python' as the arg,
    > I got an error:
    > WindowsError: [Error 2] The system cannot find the file specified
    >
    > Because the subprocess is looking for a source code location, and
    > which was hard coded, any suggestion to work out the issue?


    Famous last words, but I think it's impossible. You'd have to somehow
    specify the Python interpreter inside the py2exe-generated executable
    as the program for subprocess.Popen to run, but I sincerely doubt that
    can be done.

    I would suggest something involving os.fork(), but you're clearly on
    Windows, which doesn't support fork(), so that option's out.

    The closest thing that leaves is execfile():
    http://docs.python.org/library/functions.html#execfile

    Or you could relax your constraints:
    You could require Python to be installed on the system (I think there
    are ways to have your program's installer run the Python installer
    without any user interaction), or you could give up trying to keep the
    source code secret (it's illegal for your users to redistribute or
    modify it anyway, assuming you use the right EULA, and py2exe doesn't
    keep your sourcecode secret anyway -
    http://stackoverflow.com/questions/261638/how-do-i-protect-python-code)

    Cheers,
    Chris
    --
    http://blog.rebertia.com

    >> The subprocess call would fail utterly since sys.executable is
    >> apparently inaccurate for py2exe-generated executables.
     
    Chris Rebert, Jan 24, 2010
    #7
  8. im_smiling Guest

    Thanks for taking time to help me. If I use either way, requiring
    python being installed, or allow source codes exposure, it seems in
    some degree, there's not necessarily to make the executable package
    any more, which is very frustrating....

    Suppose I take the first way, python environment must be on a machine,
    how can I have py2exe find a specific file path, for instance as
    below, 2 up levels from running director, how to find myscript.py in
    py2exe? Since in customers' machines, C:\dev\mysricpt.py doesn't
    exist....

    python environment: running directory - C:\dev\level1\level2\test.py,
    suprocess directory-C:\dev\mysricpt.py
    py2exe C:\dev\level1\level2\dist


    On Jan 24, 1:50 pm, Chris Rebert <> wrote:
    > On Sun, Jan 24, 2010 at 10:25 AM, im_smialing <> wrote:
    > > On Jan 24, 6:35 am, Chris Rebert <> wrote:
    > >> On Sun, Jan 24, 2010 at 3:28 AM, Jonathan Hartley <> wrote:
    > >> > On Jan 22, 7:35 pm, wrote:
    > >> >> Hi,

    >
    > >> >> I need to create a python subprogress, like this:
    > >> >> myProcess = subprocess.Popen([sys.executable, 'C:\myscript.py'],
    > >> >>                                        env=env, stdin=subprocess.PIPE,
    > >> >>                                        stdout=subprocess.PIPE)

    >
    > >> >> sys.executable was printed out as ''C:\\Python25\\python.exe'', how
    > >> >> can I make this work in executable package through py2exe?

    >
    > >> >> I have to fix the following problems:
    > >> >> -Source code shouldn't exposed in an executable program
    > >> >> -Since python  environment is not required when running an executable
    > >> >> program, how to deal with the situation that "C:\\Python25\
    > >> >> \python.exe" is required as part of command?

    >
    > >> >> Thanks in advance!

    >
    > >> > Hi. What does it do when you try to execute it with py2exe? Does it
    > >> > fail to run? What is the error?

    >
    > > Thanks for pointing that, this time I try to use 'python' as the arg,
    > > I got an error:
    > > WindowsError: [Error 2] The system cannot find the file specified

    >
    > > Because the subprocess is looking for a source code location, and
    > > which was hard coded, any suggestion to work out the issue?

    >
    > Famous last words, but I think it's impossible. You'd have to somehow
    > specify the Python interpreter inside the py2exe-generated executable
    > as the program for subprocess.Popen to run, but I sincerely doubt that
    > can be done.
    >
    > I would suggest something involving os.fork(), but you're clearly on
    > Windows, which doesn't support fork(), so that option's out.
    >
    > The closest thing that leaves is execfile():http://docs.python.org/library/functions.html#execfile
    >
    > Or you could relax your constraints:
    > You could require Python to be installed on the system (I think there
    > are ways to have your program's installer run the Python installer
    > without any user interaction), or you could give up trying to keep the
    > source code secret (it's illegal for your users to redistribute or
    > modify it anyway, assuming you use the right EULA, and py2exe doesn't
    > keep your sourcecode secret anyway -http://stackoverflow.com/questions/261638/how-do-i-protect-python-code)
    >
    > Cheers,
    > Chris
    > --http://blog.rebertia.com
    >
    > >> The subprocess call would fail utterly since sys.executable is
    > >> apparently inaccurate for py2exe-generated executables.

    >
    >
     
    im_smiling, Jan 24, 2010
    #8
  9. Aahz Guest

    In article <>,
    <> wrote:
    >
    >I need to create a python subprogress, like this:
    >myProcess = subprocess.Popen([sys.executable, 'C:\myscript.py'],
    > env=env, stdin=subprocess.PIPE,
    > stdout=subprocess.PIPE)


    You need to change your setup.py so that myscript.py is also an exe.
    --
    Aahz () <*> http://www.pythoncraft.com/

    import antigravity
     
    Aahz, Jan 29, 2010
    #9
  10. Guest

    Hi, have you been able to solve this problem ??
     
    , Sep 28, 2012
    #10
  11. Miki Tebeka Guest

    Miki Tebeka, Sep 28, 2012
    #11
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Peter Nolan
    Replies:
    4
    Views:
    11,010
    E. Robert Tisdale
    Apr 8, 2004
  2. Prashant Singh

    Re: py2exe command line window problem

    Prashant Singh, Jul 22, 2003, in forum: Python
    Replies:
    0
    Views:
    400
    Prashant Singh
    Jul 22, 2003
  3. rbt

    deal or no deal

    rbt, Dec 22, 2005, in forum: Python
    Replies:
    7
    Views:
    551
    Duncan Smith
    Dec 28, 2005
  4. Karsten W.

    py2exe, command line parameter problem

    Karsten W., Aug 9, 2007, in forum: Python
    Replies:
    0
    Views:
    414
    Karsten W.
    Aug 9, 2007
  5. pycloud

    py2exe + inno from command line

    pycloud, Jun 22, 2008, in forum: Python
    Replies:
    0
    Views:
    296
    pycloud
    Jun 22, 2008
Loading...

Share This Page