The text below is selected, press Ctrl+C to copy to your clipboard. (⌘+C on Mac) No line numbers will be copied.
Guest
Python FAQ: How do I run a Python program on Windows? Examples and video tutorial
By Guest on 7th November 2022 07:01:02 AM | Syntax: PYTHON | Views: 155



New Paste New paste | Download Paste Download | Toggle Line Numbers Show/Hide line no. | Copy Paste Copy text to clipboard
  1. How do I run a .PY file on my desktop?
  2. How do I run a Python script from anywhere in Windows?
  3. Can I run a Python script in Windows without Python installed?
  4.  
  5.  
  6. How do I run a Python program on Windows?
  7. =========================================
  8.  
  9. This is not necessarily a straightforward question. If you are already
  10. familiar with running programs from the Windows command line then
  11. everything will seem obvious; otherwise, you might need a little more
  12. guidance.
  13.  
  14. Unless you use some sort of integrated development environment, you
  15. will end up *typing* Windows commands into what is referred to as a
  16. "Command prompt window".  Usually you can create such a window from
  17. your search bar by searching for "cmd".  You should be able to
  18. recognize when you have started such a window because you will see a
  19. Windows "command prompt", which usually looks like this:
  20.  
  21.    C:\>
  22.  
  23. The letter may be different, and there might be other things after it,
  24. so you might just as easily see something like:
  25.  
  26.    D:\YourName\Projects\Python>
  27.  
  28. depending on how your computer has been set up and what else you have
  29. recently done with it.  Once you have started such a window, you are
  30. well on the way to running Python programs.
  31.  
  32. You need to realize that your Python scripts have to be processed by
  33. another program called the Python *interpreter*.  The interpreter
  34. reads your script, compiles it into bytecodes, and then executes the
  35. bytecodes to run your program. So, how do you arrange for the
  36. interpreter to handle your Python?
  37.  
  38. First, you need to make sure that your command window recognises the
  39. word "py" as an instruction to start the interpreter.  If you have
  40. opened a command window, you should try entering the command "py" and
  41. hitting return:
  42.  
  43.    C:\Users\YourName> py
  44.  
  45. You should then see something like:
  46.  
  47.    Python 3.6.4 (v3.6.4:d48eceb, Dec 19 2017, 06:04:45) [MSC v.1900 32 bit (Intel)] on win32
  48.    Type "help", "copyright", "credits" or "license" for more information.
  49.    >>>
  50.  
  51. You have started the interpreter in "interactive mode". That means you
  52. can enter Python statements or expressions interactively and have them
  53. executed or evaluated while you wait.  This is one of Python's
  54. strongest features.  Check it by entering a few expressions of your
  55. choice and seeing the results:
  56.  
  57.   >>> print("Hello")
  58.   Hello
  59.   >>> "Hello" * 3
  60.   'HelloHelloHello'
  61.  
  62. Many people use the interactive mode as a convenient yet highly
  63. programmable calculator.  When you want to end your interactive Python
  64. session, call the "exit()" function or hold the "Ctrl" key down while
  65. you enter a "Z", then hit the ""Enter"" key to get back to your
  66. Windows command prompt.
  67.  
  68. You may also find that you have a Start-menu entry such as Start ‣
  69. Programs ‣ Python 3.x ‣ Python (command line) that results in you
  70. seeing the ">>>" prompt in a new window.  If so, the window will
  71. disappear after you call the "exit()" function or enter the "Ctrl-Z"
  72. character; Windows is running a single "python" command in the window,
  73. and closes it when you terminate the interpreter.
  74.  
  75. Now that we know the "py" command is recognized, you can give your
  76. Python script to it. You'll have to give either an absolute or a
  77. relative path to the Python script. Let's say your Python script is
  78. located in your desktop and is named "hello.py", and your command
  79. prompt is nicely opened in your home directory so you're seeing
  80. something similar to:
  81.  
  82.    C:\Users\YourName>
  83.  
  84. So now you'll ask the "py" command to give your script to Python by
  85. typing "py" followed by your script path:
  86.  
  87.   C:\Users\YourName> py Desktop\hello.py
  88.   hello
  89.  
  90. --
  91.  
  92. How to Run Python Programs ( .py files ) on Windows 10 ( All Options )
















Python software and documentation are licensed under the PSF License Agreement.
Starting with Python 3.8.6, examples, recipes, and other code in the documentation are dual licensed under the PSF License Agreement and the Zero-Clause BSD license.
Some software incorporated into Python is under different licenses. The licenses are listed with code falling under that license. See Licenses and Acknowledgements for Incorporated Software for an incomplete list of these licenses.

Python and it's documentation is:
Copyright © 2001-2022 Python Software Foundation. All rights reserved.
Copyright © 2000 BeOpen.com. All rights reserved.
Copyright © 1995-2000 Corporation for National Research Initiatives. All rights reserved.
Copyright © 1991-1995 Stichting Mathematisch Centrum. All rights reserved.

See History and License for complete license and permissions information:
https://docs.python.org/3/license.html#psf-license
  • Recent Pastes