How to Launch Python Files Using Windows Command Prompt

Today's TipsMake will show you how to open Python files using the built-in Command Prompt program on Windows computers. In most cases, you will open the file without any problems as long as Python is available on your device. If your computer uses an old version of Python, or you customized it when installing and did not add the 'python' command to the 'Path' variable list, proceed to add Python to the 'Path' variable list to be able to start. Run Python files through Command Prompt.

Find Python file path

Picture 1 of How to Launch Python Files Using Windows Command Prompt

Go to the directory containing the Python file. Find the Python file you want to open on Command Prompt.

If you already know the directory path of the Python file you want to open, you can open the file on Command Prompt immediately.

Picture 2 of How to Launch Python Files Using Windows Command Prompt

Select the Python file. Click on the Python file for which you want to view the directory path.

Picture 3 of How to Launch Python Files Using Windows Command Prompt

Right click on the Python file. A menu will drop down.

Picture 4 of How to Launch Python Files Using Windows Command Prompt

Click the Properties option in the drop-down menu. The Properties window will open.

Picture 5 of How to Launch Python Files Using Windows Command Prompt

Record the "Location" value. The directory address (or "path") to the right of the "Location" heading is the information you need to enter into the Command Prompt to switch to the directory containing the Python file.

You can copy a location by highlighting the information (click and drag over the "Location" value) and then press Ctrl+ C.

Launch the Python file

Picture 6 of How to Launch Python Files Using Windows Command Prompt

Open Start . Click the Windows icon in the lower left corner of the screen. The Start menu will pop up.

Picture 7 of How to Launch Python Files Using Windows Command Prompt

Find Command Prompt. Type cmdto find Command Prompt.

Picture 8 of How to Launch Python Files Using Windows Command Prompt

Click the Command Prompt program that appears at the top of the Start menu. Command Prompt will open.

Picture 9 of How to Launch Python Files Using Windows Command Prompt

Switch to the directory containing the Python file. Enter the command cdand a space, then enter the "Location" address of the Python file and press ↵ Enter.

For example, to open a Python file located in the "Files" folder on the Desktop, you need to enter cd desktop/Fileshere.

If you copied the file path, enter it cdwith a space and press Ctrl+ Vto paste the path.

Picture 10 of How to Launch Python Files Using Windows Command Prompt

Enter the command "python" along with the file name to open. Enter the command python file.py, which replaces file with the Python filename.

For example, if the Python file is named "script" then you need to enter it python script.pyhere.

If the Python file has more than one space in the name, we will enclose the name and file extension between quotation marks (e.g., python "my script.py").

Picture 11 of How to Launch Python Files Using Windows Command Prompt

Press ↵ Enter. The command will be executed and open the Python file in the Python program available on the computer.

If an error 'python' is not recognized as an internal or external commandappears after pressing Enter , you need to add Python to the PATH list and try again.

Add Python to the PATH list

Picture 12 of How to Launch Python Files Using Windows Command Prompt

Show hidden folders. Since one of the folders containing the Python installation directory is most likely hidden, we need to unhide them before continuing:

Open File Explorer.

Click the View tab.

Check the "Hidden items" box.

Picture 13 of How to Launch Python Files Using Windows Command Prompt

Go to the Python directory. In some cases, the path to Python will be "C:Python27"; however, if you installed the latest version of Python using the default settings, the program will be in a hidden folder. You can copy the appropriate file path by:

Click This PC on the left side of the File Explorer window.

Double-click the hard drive located in the "Devices and drives" section.

Scroll down and double-click the "Users" folder.

Double-click the folder with your username.

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 along with the appropriate version number (for example, "Python36").

Picture 14 of How to Launch Python Files Using Windows Command Prompt

Copy the path to the Python folder. Click the address bar at the top of the File Explorer window to highlight the content, then press Ctrl+ Cto copy the address.

Picture 15 of How to Launch Python Files Using Windows Command Prompt

Open the Power User menu. To proceed, right-click the Start icon . A menu will pop up.

You can also press ⊞ Win+ Xto open the Power User pop-up menu.

Picture 16 of How to Launch Python Files Using Windows Command Prompt

Click the System option . It's in the pop-up menu. A new window will open.

Picture 17 of How to Launch Python Files Using Windows Command Prompt

Click System info . This link is in the upper right corner of the window. The System Information window will open.

Picture 18 of How to Launch Python Files Using Windows Command Prompt

Click the Advanced system settings link . This link is in the upper left of the System Information window. At this point, another window will pop up.

Picture 19 of How to Launch Python Files Using Windows Command Prompt

Click Environment Variables… (Environment variables). This option is in the lower right corner of the pop-up window.

Picture 20 of How to Launch Python Files Using Windows Command Prompt

Find the "Path" heading in the "User variables" table. This pane is at the top of the Environment Variables window.

You may need to scroll your mouse pointer up or down on the "User variables" box to find the "Path" variable.

Picture 21 of How to Launch Python Files Using Windows Command Prompt

Double-click the "Path" heading. A window will pop up.

Picture 22 of How to Launch Python Files Using Windows Command Prompt

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

Picture 23 of How to Launch Python Files Using Windows Command Prompt

Paste the path you copied earlier. Press Ctrl+ Vto paste the content. The path you copied will appear in the text field in the middle of the window.

Picture 24 of How to Launch Python Files Using Windows Command Prompt

Click OK on the three open windows. The system will save the changes and close the three windows "Path", "Environmental Variables" and "System Properties".

Update 09 November 2023
Category

System

Mac OS X

Hardware

Game

Tech info

Technology

Science

Life

Application

Electric

Program

Mobile