Q&A for How to Use Windows Command Prompt to Run a Python File

Return to Full Article

Search
Add 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 but it does not execute it.
    Community Answer
    Community Answer
    It sounds like ptpython.exe is a command-line utility, meaning it will only start if you execute it from a DOS window - you can't create a shortcut for it directly. You can probably create a shortcut to cmd.exe, though (the DOS window) and pass it the ptpython.exe file as a parameter. Something like "cmd.exe /c ptpython.exe" should work, or if this disappears in the end, try with /k (instead of /c).
  • Question
    Does this work on Windows 7?
    Arrogance
    Arrogance
    Top Answerer
    Yes. The directions to access the environment variables would be slightly different, as there is no "Power User" menu 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's a version of Python for Windows 95).
  • Question
    After opening the Command Prompt and navigation to the directory in which the py file exists and opening Python, not able to run the file using python file_name.py. It says that the syntax is wrong.
    Arrogance
    Arrogance
    Top Answerer
    That sounds like a problem with the file you're trying to run. Make sure you are using the right version of Python for it (version 2 or 3, usually).
  • Question
    If in "PATH" variable, path of Java is already set, and we try to set path of Python there, will it affect the working of Java?
    Arrogance
    Arrogance
    Top Answerer
    No. PATH is just a list of directories for the shell to look in for programs and libraries. Adding the Python directory to the end cannot affect Java at all, as Java would come before it. Even if you added Python before Java, it could only conflict if there were program names common to both.
  • Question
    Whenever after writing the address I try to run the program but it always says that Python is not recognized as an internal or external command, operable program or batch file. What should I do?
    StickBoiMan
    StickBoiMan
    Community Answer
    This means that you cannot run files with the 'Python' command in Command Prompt or Windows Powershell IDE. Run it in the Python Shell. Usually, you can use the command 'import'. So if my file's name is hello.py, I would type 'import hello.py'. (Without the single-quotation marks.)
  • Question
    I'm getting a syntax error on the 8th line of this Python script. 1import requests 2import json 3def test(): 4567 f = open('greenbook_1956.json') 8print("Got Here"data) 9data= json.load(f). How can I fix it?
    Tinkerer02
    Tinkerer02
    Top Answerer
    Python parameters are separated by commas. Add a comma after the last quote like this: print("Got Here", data). It is also good practice to put a space after the comma. However, on line 8, 'data' does not exist yet and you will get another runtime error. Since line 9 assigns the result of 'json.load(f)' to 'data', you should move your 'print' statement to after line 9. It should then show the contents of 'data'.
Ask a Question
200 characters left
Include your email address to get a message when this question is answered.
Submit

Return to Full Article

You Might Also Like

Change Directories in Command Prompt Navigate to a Different Folder in the Command Prompt
Format a USB Using Cmd Format a USB Using CMD (Command Prompt)
Change a Computer Password Using Command Prompt Change a Windows Password Using Command Prompt
Reboot from Command Prompt on WindowsReboot from Command Prompt on Windows
Open a Folder in Cmd Open a Folder in Command Prompt (CMD)
Add Users from CMDAdd Users from CMD
Run a Batch File from the Command Line on Windows Run a Windows Batch File from the Command Line (CMD)
Open the Command Prompt in Windows5 Simple Ways to Open the Command Prompt in Windows
Open Command Prompt with a Keyboard Shortcut (Windows 8, 8.1, and 10)3 Ways to Open Command Prompt with Keyboard on Windows
Use Net SendUse Net Send
Copy Files in Command PromptCopy Files in Command Prompt
Watch Star Wars on Command Prompt Watch Star Wars via Telnet: Windows CMD & Mac Terminal
Merge Text (.Txt) Files in Command Prompt Merge Multiple Text Files in Command Prompt, Notepad, & More
Run an EXE File From Command Prompt Run an EXE File at the Windows Command Prompt