Python Forum
[split] running .py files on Windows
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[split] running .py files on Windows
#1
split from discussion https://python-forum.io/Thread-run-py-file-on-Windows

I dont mean to hijack but i kind of am doing it
Quote:From there, you can just type "hello.py".
You can just type the filename now in Windows? How do you define which python interpreter goes with which python file?
Recommended Tutorials:
Reply
#2
The OP made no mention of multiple versions of Python, but if that is the case, there are two solutions, both of which follow the Linux methods, sort of.
1) Add a shebang line (which also aids when double clicking file)
2) Specify with the "python(version) hello.py"

If there is only one version, neither method one or method two is required.
If it ain't broke, I just haven't gotten to it yet.
OS: Windows 10, openSuse 42.3, freeBSD 11, Raspian "Stretch"
Python 3.6.5, IDE: PyCharm 2018 Community Edition
Reply
#3
(Sep-14-2017, 02:50 PM)metulburr Wrote: I dont mean to hijack but i kind of am doing it
Quote:From there, you can just type "hello.py".
You can just type the filename now in Windows? How do you define which python interpreter goes with which python file? 

File associations.  Windows doesn't care about shebang lines, but if .py is associated with python, then python will be used to "open" the file, which, for python, means it'll be run.  I don't think this works in the file explorer and double clicking the file (it's just opened in your editor for... editing).  There's a special python launcher (pythonw.exe) that ships along with python, which is what file associations are bound to.  THAT will (depending on the version, I think) check for a shebang line, and try to route the script to the right version of python if it's installed.
Reply
#4
(Sep-14-2017, 03:25 PM)nilamo Wrote: Windows doesn't care about shebang lines

Beginning with Python 3.4, Windows will honor the shebang line.

Quote:double clicking the file (it's just opened in your editor for... editing).

double clicking a .py or .pyw will 'run' the script, not open it.

Quote:There's a special python launcher (pythonw.exe) that ships along with python, which is what file associations are bound to.

The 'pythonw.exe' will suppress the command terminal from starting when running a 'GUI' script, such as tkinter. 'python.exe' will open a command terminal instance which will stay open as long as the script is running. This can prove useful if you want to see Tracebacks while the script is running.

Details can be found here: https://docs.python.org/3.4/using/windows.html
If it ain't broke, I just haven't gotten to it yet.
OS: Windows 10, openSuse 42.3, freeBSD 11, Raspian "Stretch"
Python 3.6.5, IDE: PyCharm 2018 Community Edition
Reply
#5
(Sep-14-2017, 03:25 PM)nilamo Wrote: I don't think this works in the file explorer and double clicking the file (it's just opened in your editor for... editing).
It work in explorer to,will look at same place in registry \Explorer\FileExts\.py

I think is good to be used like this python hello.py.
Have several version installed use py -version,to mange all version.
C:\1                                                                         
λ py -2.7 version.py                                                         
Hello from 2.7.9 (default, Dec 10 2014, 12:24:55) [MSC v.1500 32 bit (Intel)]

C:\1
λ py -3.4 version.py
Hello from 3.4.2 (v3.4.2:ab2c023a9432, Oct  6 2014, 22:15:05) [MSC v.1600 32 bit (Intel)]

# Main version in Path always python
C:\1
λ python version.py
Hello from 3.6.1 (v3.6.1:69c0db5, Mar 21 2017, 17:54:52) [MSC v.1900 32 bit (Intel)]
I know that can use shebang(after 3.4) in windows,but i would not use.
It will just confuse people because almost no one use it.
Reply
#6
(Sep-14-2017, 04:32 PM)sparkz_alot Wrote:
(Sep-14-2017, 03:25 PM)nilamo Wrote: Windows doesn't care about shebang lines

Beginning with Python 3.4, Windows will honor the shebang line.

Well, python will honor the shebang, and run a different version of python if it needs to. Updating python to 3.4 won't change how windows works.
Reply
#7
split - merging
Recommended Tutorials:
Reply
#8
(Sep-14-2017, 04:42 PM)snippsat Wrote: I know that can use shebang(after 3.4) in windows,but i would not use. It will just confuse people because almost no one use it.

lol, I'm one of those that uses it all the time, even prior to version 3.4. Since I have 3 Linux machines (1 with 2.7 and 3.4 and 2 with 2.7, 3.4 and 3.6.2) I've just gotten in the habit of using it all the time.
Quote:Updating python to 3.4 won't change how windows works.

I don't think that even Microsoft has control any more as to how Windows works. Windows has become self-aware and now writes it's own code.  Shocked
What it does show, is that the Python gods have gone the extra mile towards making Python truly cross-platform, along with the utf-8 and Windows debacle, which Python resolved with 3.6.2 (though IMHO, it should have been MS who drops its antiquated code pages and switches to utf-8).
If it ain't broke, I just haven't gotten to it yet.
OS: Windows 10, openSuse 42.3, freeBSD 11, Raspian "Stretch"
Python 3.6.5, IDE: PyCharm 2018 Community Edition
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Class test : good way to split methods into several files paul18fr 4 486 Jan-30-2024, 11:46 AM
Last Post: Pedroski55
  Rename files in a folder named using windows explorer hitoxman 3 754 Aug-02-2023, 04:08 PM
Last Post: deanhystad
  Python script running under windows over nssm.exe JaroslavZ 0 719 May-12-2023, 09:22 AM
Last Post: JaroslavZ
  Phyton Opening files on windows C: pc EddieG 3 994 Mar-29-2023, 03:19 PM
Last Post: buran
  Split Bytearray into separate Files by Hex delimter lastyle 5 2,675 Mar-09-2023, 07:49 AM
Last Post: bowlofred
Question Take user input and split files using 7z in python askfriends 2 1,106 Dec-11-2022, 07:39 PM
Last Post: snippsat
  batch file for running python scipt in Windows shell MaartenRo 2 1,899 Jan-21-2022, 02:36 PM
Last Post: MaartenRo
  Copying files from a remote Windows station tester_V 11 6,904 Jul-17-2021, 02:19 AM
Last Post: tester_V
  Running script on multiple files Afrodizzyjack 1 2,520 May-14-2021, 10:49 PM
Last Post: Yoriz
  Flask files running order TomasAm 0 1,462 Nov-12-2020, 08:22 AM
Last Post: TomasAm

Forum Jump:

User Panel Messages

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