py2exe deal with python command line inside a program

S

susan_kijiji

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!
 
I

im_smialing

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
 
J

Jonathan Hartley

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?
 
C

Chris Rebert

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
 
I

im_smialing

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


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

im_smialing

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?
 
C

Chris Rebert

On Jan 22, 7:35 pm, (e-mail address removed) 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[/QUOTE]
 
I

im_smiling

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 22, 7:35 pm, (e-mail address removed) 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
 
A

Aahz

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top