banner



How To Run Python Code In Terminal Windows

Download Article

Download Article

Whether you're writing Python code on your Windows PC or just want to use existing Python scripts, information technology'll be helpful to learn how to run lawmaking from the Control Prompt. Running Python code is easy—yous'll just need to accept Python installed. This wikiHow article will walk you lot through opening a Python file from Command Prompt, and teach yous how to set the common "python is non recognized every bit an internal or external command" error.

  1. 1

    Go to the Python file's location. Detect the Python file that you want to open up in Command Prompt.

    • If you already know the folder path to the Python file yous desire to open, skip ahead to opening the file in Command Prompt.
  2. 2

    Select the Python file. Click once the Python file for which y'all desire to see the folder path.

    Advertisement

  3. 3

    Correct-click the Python file. Doing and then prompts a driblet-down carte to appear.

  4. four

    Click Properties . It's in the drop-down bill of fare. The properties window will open up.

  5. 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 lot can copy the location by highlighting it (click and drag your mouse across the "Location" value) and so pressing Ctrl+C .

    Advertizement

  1. 1

    Open Outset . Click the Windows logo in the bottom-left corner of the screen. The Start bill of fare will popular up.

  2. 2

    Search for Command Prompt. Type in cmd to do so.

  3. three

    Click Command Prompt. It'southward at the top of the Start carte. Doing so volition open Command Prompt.

  4. 4

    Switch to your Python file's directory. Type cd and a space, and so blazon in the "Location" accost for your Python file and press Enter .

    • For example, to open up a Python file in a folder named "Files" on your Desktop, you would enter cd desktop/Files here.
    • If you copied the path to the file, you lot can type in cd and a space and then press Ctrl+V to paste in the path.
  5. v

    Enter the "python" control and your file'due south proper noun. Blazon in python file.py where file is your Python file's proper noun.

    • For example, if your Python file is named "script", you would type in python script.py hither.
    • If your Python file has one or more spaces in its name, you lot'll identify quotation marks around the file name and extension (eastward.thousand., python "my script.py").
  6. 6

    Press Enter . Doing so runs your command and opens your Python file via your reckoner'southward installed Python plan.

    • If yous run into an error that says 'python' is not recognized as an internal or external control afterward pressing Enter, you'll need to add Python to the PATH listing before retrying this office.

    Advertizing

  1. one

    Enable viewing for hidden folders. Since one of the folders that contains your Python installation binder is most probable hidden, you lot'll take to unhide it before proceeding:

    • Open File Explorer .
    • Click the View tab.
    • Check the "Hidden items" box.
  2. 2

    Navigate to your Python folder. In some cases, the Python path is "C:\Python27"; withal, if you've installed the most contempo version of Python using the default settings, it's tucked abroad in a hidden folder. Y'all tin 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".
    • Curlicue down and double-click "Programs".
    • Double-click the "Python" folder.
    • Double-click the Python folder with your preferred version number (eastward.k., "Python36").
  3. iii

    Re-create the path to the Python folder. Click once the address bar at the top of the File Explorer to highlight its contents, and so press Ctrl+C to copy the highlighted accost.

  4. four

    Open the Power User menu. Right-click the Starting time

    icon to do so. You should see a pop-upwards menu appear.

    • You can also press Win+Ten to open the Power User pop-up bill of fare.
  5. 5

    Click Organization . Information technology's in the popular-up carte. A new window volition open.

  6. 6

    Click System info . This is a link in the upper-right corner of the window. Doing and then opens the System Data window.

  7. 7

    Click the Advanced arrangement settings link. You'll see this in the upper-left side of the Arrangement Information window. Yet another window will pop up.

  8. eight

    Click Environment Variables… . It's in the bottom-right corner of the pop-upward window.

  9. 9

    Observe the "Path" heading in the "User variables" pane. This window is at the pinnacle of the Environment Variables window.

    • You lot may accept to gyre upward or downward with your mouse cursor hovering over the "User variables" pane to find the "Path" variable.
  10. 10

    Double-click the "Path" heading. Doing so opens a pop-upward window.

  11. 11

    Click New . It's on the right side of the window. A text field will open in the middle of the window.

  12. 12

    Paste in your copied path. Press Ctrl+5 to do and then. Your copied path will announced in the text field in the middle of the window.

  13. xiii

    Click OK on the 3 open windows. This volition save your changes and shut the "Path" window, the "Ecology Variables" window, and the "System Backdrop" window.

    Advertizing

Add together New Question

  • Question

    I want to create a shortcut that executes the utility "ptpython," running in the cmd prompt. The shortcut I have points to the directory containing "ptpython.exe" file only it does not execute it.

    Community Answer

    It sounds like ptpython.exe is a command-line utility, meaning information technology will only start if yous execute it from a DOS window - you lot can't create a shortcut for it directly. Y'all tin probably create a shortcut to cmd.exe, though (the DOS window) and laissez passer it the ptpython.exe file as a parameter. Something like "cmd.exe /c ptpython.exe" should work, or if this disappears in the end, attempt with /m (instead of /c).

  • Question

    Does this work on Windows seven?

    Arrogance

    Yes. The directions to admission the environment variables would exist slightly different, as there is no "Power User" carte du jour in Windows 7. Instead: 1. Press the Windows key and R to open the Run dialog. 2. Enter "sysdm.cpl". 3. Click the "Advanced" tab of the System Properties Window. 4. Click the "Environmental variables". Most everything else would work as described even on Windows 95 (if there'south a version of Python for Windows 95).

  • Question

    Afterwards opening the Command Prompt and navigation to the directory in which the py file exists and opening Python, non able to run the file using python file_name.py. Information technology says that the syntax is wrong.

    Arrogance

    That sounds like a problem with the file you lot're trying to run. Make sure you lot are using the right version of Python for it (version ii or 3, ordinarily).

  • Question

    If in "PATH" variable, path of Java is already set, and we try to set path of Python there, volition it affect the working of Java?

    Arrogance

    No. PATH is just a list of directories for the shell to expect in for programs and libraries. Calculation the Python directory to the end cannot impact Java at all, every bit Java would come before it. Even if you added Python before Java, information technology could only conflict if there were program names common to both.

  • Question

    Whenever after writing the address I attempt to run the plan only it ever says that Python is not recognized as an internal or external command, operable plan or batch file. What should I exercise?

    StickBoiMan

    StickBoiMan

    Community Answer

    This means that yous cannot run files with the 'Python' command in Command Prompt or Windows Powershell IDE. Run it in the Python Shell. Usually, you tin apply the command 'import'. So if my file'southward proper noun is hello.py, I would type 'import hello.py'. (Without the single-quotation marks.)

Ask a Question

200 characters left

Include your email address to get a message when this question is answered.

Submit

Advertising

About This Article

Thanks to all authors for creating a folio that has been read 593,486 times.

Is this article upwards to date?

Source: https://www.wikihow.com/Use-Windows-Command-Prompt-to-Run-a-Python-File

Posted by: crusecamen1959.blogspot.com

0 Response to "How To Run Python Code In Terminal Windows"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel