How to Use Windows Command Prompt to Run a Python File

Part 1 of 3:

Finding the Python File Path

  1. How to Use Windows Command Prompt to Run a Python File Picture 1
    Go to the Python file's location. Find the Python file that you want to open in Command Prompt.
    1. If you already know the folder path to the Python file you want to open, skip ahead to opening the file in Command Prompt.
  2. How to Use Windows Command Prompt to Run a Python File Picture 2
    Select the Python file. Click once the Python file for which you want to see the folder path.
  3. How to Use Windows Command Prompt to Run a Python File Picture 3
    Right-click the Python file. Doing so prompts a drop-down menu to appear.
  4. How to Use Windows Command Prompt to Run a Python File Picture 4
    Click Properties. It's in the drop-down menu. The properties window will open.
  5. How to Use Windows Command Prompt to Run a Python File Picture 5
    Note the "Location" value. The folder address (or "path") to the right of the "Location" heading is what you'll need to enter into Command Prompt when switching to the directory in which your Python file is stored.
    1. You can copy the location by highlighting it (click and drag your mouse across the "Location" value) and then pressing Ctrl+C.
Part 2 of 3:

Running a Python File

  1. How to Use Windows Command Prompt to Run a Python File Picture 6
    Open Start
    How to Use Windows Command Prompt to Run a Python File Picture 7
    . Click the Windows logo in the bottom-left corner of the screen. The Start menu will pop up.
  2. How to Use Windows Command Prompt to Run a Python File Picture 8
    Search for Command Prompt. Type in cmd to do so.
  3. How to Use Windows Command Prompt to Run a Python File Picture 9
    Click
    How to Use Windows Command Prompt to Run a Python File Picture 10
    Command Prompt. It's at the top of the Start menu. Doing so will open Command Prompt.
  4. How to Use Windows Command Prompt to Run a Python File Picture 11
    Switch to your Python file's directory. Type cd and a space, then type in the "Location" address for your Python file and press Enter.
    1. For example, to open a Python file in a folder named "Files" on your Desktop, you would enter cd desktop/Files here.
    2. If you copied the path to the file, you can type in cd and a space and then press Ctrl+V to paste in the path.
  5. How to Use Windows Command Prompt to Run a Python File Picture 12
    Enter the "python" command and your file's name. Type in python file.py where file is your Python file's name.
    1. For example, if your Python file is named "script", you would type in python script.py here.
    2. If your Python file has one or more spaces in its name, you'll place quotation marks around the file name and extension (e.g., python "my script.py").
  6. How to Use Windows Command Prompt to Run a Python File Picture 13
    Press Enter. Doing so runs your command and opens your Python file via your computer's installed Python program.
    1. If you encounter an error that says 'python' is not recognized as an internal or external command after pressing Enter, you'll need to add Python to the PATH list before retrying this part.
Part 3 of 3:

Adding Python to the PATH List

  1. How to Use Windows Command Prompt to Run a Python File Picture 14
    Enable viewing for hidden folders. Since one of the folders that contains your Python installation folder is most likely hidden, you'll have to unhide it before proceeding:
    1. Open File Explorer
      How to Use Windows Command Prompt to Run a Python File Picture 15
      .
    2. Click the View tab.
    3. Check the "Hidden items" box.
  2. How to Use Windows Command Prompt to Run a Python File Picture 16
    Navigate to your Python folder. In some cases, the Python path is "C:Python27"; however, if you've installed the most recent version of Python using the default settings, it's tucked away in a hidden folder. You can copy the proper file path by doing the following:
    1. Click This PC on the left side of the File Explorer.
    2. Double-click your hard drive in the "Devices and drives" section.
    3. Scroll down and double-click the "Users" folder.
    4. Double-click the folder with your username on it.
    5. Scroll down and double-click "AppData".
    6. Double-click "Local".
    7. Scroll down and double-click "Programs".
    8. Double-click the "Python" folder.
    9. Double-click the Python folder with your preferred version number (e.g., "Python36").
  3. How to Use Windows Command Prompt to Run a Python File Picture 17
    Copy the path to the Python folder. Click once the address bar at the top of the File Explorer to highlight its contents, then press Ctrl+C to copy the highlighted address.
  4. How to Use Windows Command Prompt to Run a Python File Picture 18
    Open the Power User menu. Right-click the Start
    How to Use Windows Command Prompt to Run a Python File Picture 19
    icon to do so. You should see a pop-up menu appear.
    1. You can also press Win+X to open the Power User pop-up menu.
  5. How to Use Windows Command Prompt to Run a Python File Picture 20
    Click System. It's in the pop-up menu. A new window will open.
  6. How to Use Windows Command Prompt to Run a Python File Picture 21
    Click System info. This is a link in the upper-right corner of the window. Doing so opens the System Information window.
  7. How to Use Windows Command Prompt to Run a Python File Picture 22
    Click the Advanced system settings link. You'll see this in the upper-left side of the System Information window. Yet another window will pop up.
  8. How to Use Windows Command Prompt to Run a Python File Picture 23
    Click Environment Variables…. It's in the bottom-right corner of the pop-up window.
  9. How to Use Windows Command Prompt to Run a Python File Picture 24
    Find the "Path" heading in the "User variables" pane. This window is at the top of the Environment Variables window.
    1. You may have to scroll up or down with your mouse cursor hovering over the "User variables" pane to find the "Path" variable.
  10. How to Use Windows Command Prompt to Run a Python File Picture 25
    Double-click the "Path" heading. Doing so opens a pop-up window.
  11. How to Use Windows Command Prompt to Run a Python File Picture 26
    Click New. It's on the right side of the window. A text field will open in the middle of the window.
  12. How to Use Windows Command Prompt to Run a Python File Picture 27
    Paste in your copied path. Press Ctrl+V to do so. Your copied path will appear in the text field in the middle of the window.
  13. How to Use Windows Command Prompt to Run a Python File Picture 28
    Click OK on the three open windows. This will save your changes and close the "Path" window, the "Environmental Variables" window, and the "System Properties" window.
4 ★ | 1 Vote

May be interested

  • Add Command Prompt to Power User Menu on Windows 10Add Command Prompt to Power User Menu on Windows 10
    on windows 10 build 14971, microsoft replaced command prompt and command prompt (admin) with windows powershell. according to microsoft, this change will bring the best command line experience to users. but in fact, users prefer to use command prompt rather than using powershell.
  • Instructions for using Command PromptInstructions for using Command Prompt
    deep in windows is a command-line world that is obscure. in this article, we will show you how to solve errors and make your computer more secure.
  • How to change the folder in Command Prompt on Windows 10How to change the folder in Command Prompt on Windows 10
    one of the first things you need to learn when you become more familiar with the command prompt on windows 10 is how to change the folders in the file system of the operating system. the following article will guide you to implement them.
  • 10 useful commands in Windows you should know10 useful commands in Windows you should know
    command prompt is used to execute batch files, perform tasks quickly, help you troubleshoot and solve some windows problems when the system crashes. however, not all commands in windows are useful and must be done regularly. with the 10 command lines in the following article it is very useful even if you are not an administrator.
  • 6 Cool Tricks You Can Do in Windows Command Prompt6 Cool Tricks You Can Do in Windows Command Prompt
    command prompt has a ton of capabilities, and many people doubt they know what a few lines of code can do. next time you're bored with your pc, try these cool command prompt tricks for yourself.
  • How to Unblock Command Prompt AnywhereHow to Unblock Command Prompt Anywhere
    have you ever been at school and discovered that the it administrators blocked the command prompt? or did you try to do a command and it says 'access is denied'? this article will explain how to bypass these restrictions using simple...
  • How to Customize the Font in Windows Command PromptHow to Customize the Font in Windows Command Prompt
    many people work regularly with the windows command prompt. one of the main problems users encounter, however, is the difficulty of achieving the same look every time one works with the command prompt interface. this article is intended to...
  • 6 Best Command Prompt Alternatives for Windows6 Best Command Prompt Alternatives for Windows
    do you find the command prompt a bit complicated and feel you need a tool that is easier to use? this is where other terminal emulators come into play!
  • How to Copy Files in Command PromptHow to Copy Files in Command Prompt
    this wikihow teaches you how to use windows' command prompt program to copy a file or folder. find out your file's location. you'll need the file's location—also known as a 'directory'—in order to tell command prompt where to look for the f...
  • How to Create a Custom Windows Command PromptHow to Create a Custom Windows Command Prompt
    the windows command prompt (located at c:windowssystem32cmd.exe) is a useful tool to perform various administrative tasks. the prompt is a string of characters (special and non special) that are displayed whenever the command prompt is...