py2exe deal with python command line inside a program

Chris Rebert clp2 at rebertia.com
Sun Jan 24 13:50:50 EST 2010


On Sun, Jan 24, 2010 at 10:25 AM, im_smialing <susan_kijiji at yahoo.ca> wrote:
> On Jan 24, 6:35 am, Chris Rebert <c... at rebertia.com> wrote:
>> On Sun, Jan 24, 2010 at 3:28 AM, Jonathan Hartley <tart... at tartley.com> wrote:
>> > On Jan 22, 7:35 pm, susan_kij... at yahoo.ca 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.



More information about the Python-list mailing list