For the record (I know it's offtopic, but...) here's a program that does
exactly what your batch file does, and has the same limitations:
specifically, it requires python.exe to be in the path. It's all of 22
lines of C, which is mostly some fiddling with arguments and error
checking. I've built an executable with MSVC8, but you can compile it
with GCC or anything else -- it's as vanilla as C gets.
I'm posting to the list in the hope this may help someone else in the
(The attachment is a zip file containing C source, an executable, and a
Python test script. I've renamed to stub.zip.bin to get past the
Daniel Pryden wrote:
> Just curious: if you're going to want to invoke it from a Python
> process anyway (using subprocess.Popen or friends) then why not make
> your Python program notice that it's trying to launch a Python script
> and do an execfile instead? Or even parse the command line (I'm
> presuming you want to mix and match Python scripts and other
> executables) and look at the file extension: .exe and .com executed
> directly, .bat and .cmd get executed through the shell, .py through
> execfile or spawn a new Python executable, etc.
> Alternatively, it seems like a simple programming job in C to write a
> small stub that finds the Python environment via the registry and
> invokes it. (I know of several comparable launcher stubs for Java:
> winrun4j.sf.net and javaservice.objectweb.org come immediately to
> mind.) You could write a simple launcher stub in about 10-20 lines of
> C# but I don't think you want the .NET dependency. Straight Win32 C
> is a bit more complex but not impossibly so. You don't need any
> commercial tools: MinGW is probably sufficient. Build it once and you
> probably won't even need to recompile it ever again. Heck, if there
> isn't already a sourceforge project for what you describe, somebody
> should start one.
> However, this is definitely getting quite off-topic for the py2exe list.
> - Daniel.
> Geoff Bache wrote:
>> Thomas Heller wrote:
>>> Geoff Bache schrieb:
>>>>>> However, as the application as a whole requires Python to be
>>>>>> installed anyway it feels a bit odd to be distributing things copied
>>>>>> directly from the python distribution. Is there some way to tell
>>>>>> py2exe not to do that and create an executable that can
>>>>>> find a python distribution from the registry and use the files from
>>>>> I believe that setuptools (when creating eggs?) does create small
>>>>> executables for the scripts, so this may be a better way for you.
>>>> Thanks. It now occurs to me that perhaps all I need is a Windows
>>>> batch file that
>>>> does something like
>>>> python myscript.py $*
>>>> except I can't figure out how to do the UNIX "$*" on Windows. Any
>>> python myscript.py %*
>>> It requires that python.exe is on the PATH; the following might also
>>> since .py files are associated with python.exe:
>>> myscript.py %*
>> Thanks for the tips. That seems to work, as far as it goes, but it
>> seems I did need a .exe file after all...
>> otherwise it only works when the program is started via the shell...
>> If I create myscript.bat and from a python prompt run
>> this fails. With shell=True it works. However if I have myscript.exe
>> instead it works with or
>> without the shell... So now I need to either compile the .bat file
>> (which seems like it requires commercial
>> tools, grrr) or figure out setuptools. Or is there some other way to
>> do this?
>> (I'm basically trying to replicate the #!/usr/bin/env python syntax
>> from UNIX, which works with or without
>> the shell being explicitly used on startup)
>> Check out the new SourceForge.net Marketplace.
>> It's the best place to buy or sell services for
>> just about anything Open Source.