How To Run Python In Command Prompt

In this article I will show you how to run a Python program on the command prompt.

Image for post
Image for post

Step 0: Check That You’ve Installed Python

To easily check if you have python already installed on your computer, you can open the command prompt and check for a Python version. This will be good to also see what version of python you have if you do have python already installed.

Open the command prompt and type the following:

python --version

Note: I am using Python version 3.8.3

If you do not get back a python version then you will need to go to the website to install python onto your computer.

Step 1: Create the Python Program File

Create your Python program. We will create a simple Python program using notepad that prints ‘Hello,World’ and save it as on the desktop.

Image for post
Image for post
Example of the file

Step 2: Change Directories

Now that the file has been created, we will open up the command prompt and go to the directory that contains the python executable file.

Image for post
Image for post
Image of the command prompt

Open the command prompt and change the directory to the directory where you installed Python. You can find the command below.

Note: My directory name is Python38–32

cd C:\Python38-32

Step 3: Run the Python Program

In this directory we can use the python command to run and execute the python file that was created on the desktop. Be sure to put the full location of the python file that was created in step 1. Your next command should look similar to the below example.

Note: The <username> in the below command is only a place holder for your user name, be sure to replace it with your actual user name.

python "C:\Users\<username>\Desktop\"

Now “Hello, World” should be printed in the command prompt ! That’s it, we are all done ! If you want, you can also check out the video below for extra material !

If you are also interested in reading more on Python one of the fastest growing programming languages that many companies and computer science departments use, then I recommend you check out the book Learning Python written by Mark Lutz’s.

Image for post
Image for post

Learning Python

Thanks for reading this article I hope it’s helpful to you all! If you enjoyed this article and found it helpful please leave some claps to show your appreciation. Keep up the learning, and if you like Python, machine learning, mathematics, computer science, programming or algorithm analysis, please visit and subscribe to my YouTube channels (randerson112358 & compsci112358 ).

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store