Python Forum
launch .PY program Help
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
launch .PY program Help
#11
Hello,

You can always find out which version of python is running by typing

# For version 2.5 up to current version
python --version
# prior to 2.5 you will need:
python -c 'import sys; print(sys.version)'
from the command window (Start-->cmd)

The default version is determined by your system path,


from command window, type 'path'

You can find the python version in the string, should look similar to 'C:\Python34;', where 34 = version 3.4

Larz60+
Reply
#12
If you just fire up python in the cmd (console) like:

C:\ > python
it will print the version before the interpreter prompt. At least in Linux that is what is happens. I think in Windows should be the same.

And there is no reason to copy/move the script in the directory where python.exe is located. You always can point to script with its full path.
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply
#13
(Sep-29-2016, 10:26 AM)wavic Wrote: it will print the version before the interpreter prompt. At least in Linux that is what is happens. I think in Windows should be the same.

And there is no reason to copy/move the script in the directory where python.exe is located. You always can point to script with its full path.
It will work the same,but then need Environment Variables(Path) to be setup on Windows,
then python command will work from anywhere in cmd.

Python 3.5 has a box that can be check under installation,all earlier version has to a add to Path self.
So eg for Python 3.4 need to add ;C:\python34\;C:\python34\scripts to Path.
Reply
#14
I don't use Windows but I think you could edit the file and put either:
#!c:\python34\python
or
#!c:\python27\python 
As the first line in the sna.py file and it should run by double clicking it or running it from the command line
Reply
#15
Windows doesn't use the Shebang.
Reply
#16
(Oct-18-2016, 07:48 PM)micseydel Wrote: Windows doesn't use the Shebang.

That looks like it might not actually be true anymore: https://docs.python.org/3/using/windows....bang-lines
Or rather, new versions of the windows python launcher associate with files that don't have an extension, and maybe check to see if that file should be handled by python.

I think you'd still have to mark the file as executable, which is... not something I'd recommend.
Reply
#17
I don't see anything there suggesting a shebang is used on Windows. It just seems to say that since it's a comment, it's cross-compatible with Windows in the sense that Windows can ignore it.
Reply
#18
I just added "#! /usr/bin/python -v" to the top of a random python file, and ran it using "test.py" from the command line, not giving any indication (aside from file extension) that it was a python file. I also DID NOT mark the file executable.

And I saw a very large amount of verbose info that's normally never there.

So either windows is parsing shebangs, or python is :p
Reply
#19
(Oct-18-2016, 08:39 PM)nilamo Wrote: I just added "#! /usr/bin/python -v" to the top of a random python file, and ran it using "test.py" from the command line, not giving any indication (aside from file extension) that it was a python file.  I also DID NOT mark the file executable.

And I saw a very large amount of verbose info that's normally never there.

So either windows is parsing shebangs, or python is :p
Do you have file extension .py associated with the python interpreter? Mine does this also but it is not because there is a shebang in the code...but because of file associations. A sure way to confirm this is to remove the file extension and rerun.
Recommended Tutorials:
Reply
#20
Ah, I see now. Yes, it's the Python launcher doing it. Windows itself still doesn't do anything with the shebang. I did learn something new about Python's Windows launcher here though :)

It looks like it implies that if you specify a version as you would with Unix, that it'll work on Windows. Can anyone verify that? Also, I'd be a little surprised if the Windows path works on Windows, but even if it does, it seems a Unix shebang should be used for portability.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Using tkinter on Windows to launch python 3 scripts Mocap 1 2,739 Jul-17-2019, 05:16 AM
Last Post: Yoriz
  Launch pdf and close on delete window event ashtona 6 5,674 Mar-22-2018, 03:04 PM
Last Post: ashtona

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020