Clear, practical technology insights BSOD Code Lookup · Windows Error Code Lookup · Wi-Fi Troubleshooting · PC Troubleshooting Checklist

How to Use Windows Command Prompt to Run a Python File

Learn how to use Windows command prompt to run a python file with clear steps, practical context, and useful troubleshooting guidance.

Table of Contents

This updated guide examines How to Use Windows Command Prompt to Run a Python File and organizes the essential facts, background, and practical takeaways in clear American English.

Part 1of 3:

Finding the Python File Path

  1. How to Use Windows Command Prompt to Run a Python File — contextual image 1 Go to the Python file's location. Find the Python file that you want to open in Command Prompt.
    • 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 — contextual image 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 — contextual image 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 — contextual image 4 ClickProperties. It's in the drop-down menu. The properties window will open.
  5. How to Use Windows Command Prompt to Run a Python File — contextual image 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.
    • You can copy the location by highlighting it (click and drag your mouse across the "Location" value) and then pressingCtrl+C.

Part 2of 3:

Running a Python File

  1. How to Use Windows Command Prompt to Run a Python File — contextual image 6 Open StartHow to Use Windows Command Prompt to Run a Python File — contextual image 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 — contextual image 8 Search for Command Prompt. Type incmdto do so.
  3. How to Use Windows Command Prompt to Run a Python File — contextual image 9 ClickHow to Use Windows Command Prompt to Run a Python File — contextual image 10Command 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 — contextual image 11 Switch to your Python file's directory. Typecdand a space, then type in the "Location" address for your Python file and press?Enter.
    • For example, to open a Python file in a folder named "Files" on your Desktop, you would entercd desktop/Fileshere.
    • If you copied the path to the file, you can type incdand a space and then pressCtrl+Vto paste in the path.
  5. How to Use Windows Command Prompt to Run a Python File — contextual image 12 Enter the "python" command and your file's name. Type inpython file.pywhere file is your Python file's name.
    • For example, if your Python file is named "script", you would type inpython script.pyhere.
    • 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 — contextual image 13 Press?Enter. Doing so runs your command and opens your Python file via your computer's installed Python program.
    • If you encounter an error that says'python' is not recognized as an internal or external commandafter pressing Enter , you'll need to add Python to the PATH list before retrying this part.

Part 3of 3:

Adding Python to the PATH List

  1. How to Use Windows Command Prompt to Run a Python File — contextual image 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:
    • Open File ExplorerHow to Use Windows Command Prompt to Run a Python File — contextual image 15.
    • Click the View tab.
    • Check the "Hidden items" box.
  2. How to Use Windows Command Prompt to Run a Python File — contextual image 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:
    • Click This PC on the left side of the File Explorer.
    • Double-click your hard drive in the "Devices and drives" section.
    • Scroll down and double-click the "Users" folder.
    • Double-click the folder with your username on it.
    • Scroll down and double-click "AppData".
    • Double-click "Local".
    • Scroll down and double-click "Programs".
    • Double-click the "Python" folder.
    • 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 — contextual image 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 pressCtrl+Cto copy the highlighted address.
  4. How to Use Windows Command Prompt to Run a Python File — contextual image 18 Open the Power User menu. Right-click the Start How to Use Windows Command Prompt to Run a Python File — contextual image 19icon to do so. You should see a pop-up menu appear.
    • You can also press?Win+Xto open the Power User pop-up menu.
  5. How to Use Windows Command Prompt to Run a Python File — contextual image 20 ClickSystem. It's in the pop-up menu. A new window will open.
  6. How to Use Windows Command Prompt to Run a Python File — contextual image 21 ClickSystem 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 — contextual image 22 Click theAdvanced system settingslink. 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 — contextual image 23 ClickEnvironment 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 — contextual image 24 Find the "Path" heading in the "User variables" pane. This window is at the top of the Environment Variables window.
    • 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 — contextual image 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 — contextual image 26 ClickNew. 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 — contextual image 27 Paste in your copied path. PressCtrl+Vto 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 — contextual image 28 ClickOKon the three open windows. This will save your changes and close the "Path" window, the "Environmental Variables" window, and the "System Properties" window.

FAQ

What is How to Use Windows Command Prompt to Run a Python File about?

It provides a structured overview of python, explains the main context, and highlights practical takeaways for readers.

Why does this topic matter?

Understanding the main concepts helps readers evaluate the issue, avoid common mistakes, and make better-informed decisions.

How should readers use this information?

Use the guidance as a practical starting point, confirm details that may have changed, and follow current product, safety, or security recommendations.

Discussion

Reader Comments 0

Sign in with email or Google to join the discussion.