py2exe deal with python command line inside a program

im_smiling susan_kijiji at yahoo.ca
Sun Jan 24 22:17:44 CET 2010


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 <c... at rebertia.com> wrote:
> On Sun, Jan 24, 2010 at 10:25 AM, im_smialing <susan_kij... 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