- How do I run a .PY file on my desktop?
- How do I run a Python script from anywhere in Windows?
- Can I run a Python script in Windows without Python installed?
- How do I run a Python program on Windows?
- =========================================
- This is not necessarily a straightforward question. If you are already
- familiar with running programs from the Windows command line then
- everything will seem obvious; otherwise, you might need a little more
- guidance.
- Unless you use some sort of integrated development environment, you
- will end up *typing* Windows commands into what is referred to as a
- "Command prompt window". Usually you can create such a window from
- your search bar by searching for "cmd". You should be able to
- recognize when you have started such a window because you will see a
- Windows "command prompt", which usually looks like this:
- C:\>
- The letter may be different, and there might be other things after it,
- so you might just as easily see something like:
- D:\YourName\Projects\Python>
- depending on how your computer has been set up and what else you have
- recently done with it. Once you have started such a window, you are
- well on the way to running Python programs.
- You need to realize that your Python scripts have to be processed by
- another program called the Python *interpreter*. The interpreter
- reads your script, compiles it into bytecodes, and then executes the
- bytecodes to run your program. So, how do you arrange for the
- interpreter to handle your Python?
- First, you need to make sure that your command window recognises the
- word "py" as an instruction to start the interpreter. If you have
- opened a command window, you should try entering the command "py" and
- hitting return:
- C:\Users\YourName> py
- You should then see something like:
- Python 3.6.4 (v3.6.4:d48eceb, Dec 19 2017, 06:04:45) [MSC v.1900 32 bit (Intel)] on win32
- Type "help", "copyright", "credits" or "license" for more information.
- >>>
- You have started the interpreter in "interactive mode". That means you
- can enter Python statements or expressions interactively and have them
- executed or evaluated while you wait. This is one of Python's
- strongest features. Check it by entering a few expressions of your
- choice and seeing the results:
- >>> print("Hello")
- Hello
- >>> "Hello" * 3
- 'HelloHelloHello'
- Many people use the interactive mode as a convenient yet highly
- programmable calculator. When you want to end your interactive Python
- session, call the "exit()" function or hold the "Ctrl" key down while
- you enter a "Z", then hit the ""Enter"" key to get back to your
- Windows command prompt.
- You may also find that you have a Start-menu entry such as Start ‣
- Programs ‣ Python 3.x ‣ Python (command line) that results in you
- seeing the ">>>" prompt in a new window. If so, the window will
- disappear after you call the "exit()" function or enter the "Ctrl-Z"
- character; Windows is running a single "python" command in the window,
- and closes it when you terminate the interpreter.
- Now that we know the "py" command is recognized, you can give your
- Python script to it. You'll have to give either an absolute or a
- relative path to the Python script. Let's say your Python script is
- located in your desktop and is named "hello.py", and your command
- prompt is nicely opened in your home directory so you're seeing
- something similar to:
- C:\Users\YourName>
- So now you'll ask the "py" command to give your script to Python by
- typing "py" followed by your script path:
- C:\Users\YourName> py Desktop\hello.py
- hello
- --
- 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