making a python program in windows

R

Rustom Mody

I know how to make a python script behave like a (standalone) program
in unix --
1. put a #! path/to/python as the first line
2. make the file executable

The closest I know how to do this in windows is:
r-click the file in win-explorer
goto properties
goto open with
change pythonw to python

Can someone enlighten me about a more scriptish way of doing this?
Basically if I have to setup that program on other (windows) m/cs is
there some .bat or .vbs or some regedit thingy Ive to do to avoid the
Rt-click routine?
 
R

rustom

Since you don't know for sure if a Python environment is available on
the other windows machine and whether the file associations are
configured correctly, the best thing you can do is to use something like
py2exe and distribute the result of that.

Oh - Oh! Not an exe please! I dont want to move away from readable
text files if possible.

I certainly know that python2.6 is installed.
Why that installation by default does not put python.exe on the path I
dont know but that is best corrected by hand.

Bottom Line: Assume that from a command line (cmd) python runs and
gives its interpreter prompt.
When run from cygwin it hangs but thats another story. Just dont
assume cygwin.

i suppose the question is entirely about setting properly (and
grokking) file associations -- why is a .py file associated with
pythonw and not python? And is making this association right enough to
make a .py file in windows behave like a shebang file in unix?

[And is there a more appropriate list for such questions?]

Thanks
 
R

rustom

I think the question about the file association is one you have to answer
for yourself. When you install Python it associates .pyw with pythonw and
.py with python. If something on your system has changed this the best
thing you can do is to change it back.

Try typing the following commands and then fixing any differences by typing
the expected output as the command parameter
(e.g. "assoc .py=Python.File"):

C:\>assoc .py
.py=Python.File

C:\>assoc .pyw
.pyw=Python.NoConFile

C:\>ftype Python.file
Python.file="C:\Python26\python.exe" "%1" %*

C:\>ftype Python.NoConFile
Python.NoConFile="C:\Python26\pythonw.exe" "%1" %*

Thanks for this (and all other) tips.
Strangely now my m/c shows things exactly like so. A new .py file gets
associated with python but two days ago it was with pythonw?!
Any recos on where I could read up on this stuff?
 
T

Tim Golden

rustom said:
Thanks for this (and all other) tips.
Strangely now my m/c shows things exactly like so. A new .py file gets
associated with python but two days ago it was with pythonw?!
Any recos on where I could read up on this stuff?

I by "all this stuff" you mean: Windows file associations,
then this would be the place:

http://msdn.microsoft.com/en-us/library/dd758090(VS.85).aspx

If you mean: what the Python installer does to set such
things up, then there is some information here:

http://docs.python.org/using/windows.html

but not really covering the exact question you've
been asking. You'd have to hunt around the archives
of this mailing list and/or look at the msi source:

http://svn.python.org/view/python/trunk/Tools/msi/msi.py?view=markup

(and feel free to submit a doc patch if you think it might help)

TJG
 

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,768
Messages
2,569,574
Members
45,050
Latest member
AngelS122

Latest Threads

Top