Install Python and run first Python

Install Python & Run First Python program – Learn Python with me

In this post, we will learn about running your first Python program. To do that, you would need the Python software to be installed on your machine. So, we will look at the installation of Python first and then run a Python program later.

How to install Python on Windows?

I am sorry if you are Linux or Mac user. Since I am a Windows user, I will share only about installing Python on Windows machines. However, the installation steps are pretty much the same on other operating systems as well. I will, anyways, update this post in the future with MacOS installation steps for Python software. So, you might want to bookmark this webpage to your browser to keep a tab on future updates of this webpage.

Please follow the steps below to install Python on your machine.

  • Open the official website of Python: https://www.python.org/
  • Hover over the download tab and click on Python 3.9.5 button, as shown in the screenshot below. 3.9.5 is the current version today, and the version number might differ if you are viewing this post later.
Install Python for Windows Screenshot 1
  • Clicking the button in the screenshot above will save a file, python-3.9.5-amd64, to the Downloads folder.
  • Double click the downloaded file, select the checkbox, Add Python 3.9 to PATH, and click on Install Now, as shown in the screenshot below.
Install Python for Windows Screenshot 2

Once the Python installation is finished, you will see “Setup was successful” in the installation window, as shown in the screenshot below.

Install Python for Windows Screenshot 4

Also Read: Python Introduction

How to verify the installation of Python?

It is a human instinct to test things and that’s why we will learn how to verify the installation of Python.

Please follow the steps below to verify the installation of the Python

  • Click Start Button on the taskbar.
  • Go to Python 3.9 folder, and you should find the items shown on the screenshot below
Python 3.9 applications
  • If you can also see the same items shown on the screenshot above, it means that Python is installed successfully on your machine

How to verify the path of Python?

The Python installation process takes care of setting up the Python path. However, it is still worth it to verify whether the path of Python is added in your system settings or not.

Please follow the steps below to verify the Python path in your Windows machine

  • Right-click the ‘This PC‘ icon on your desktop and choose Properties
  • Click on Advanced system settings on the screen, and it will pop up a small window, as shown in the screenshot below
System Properties Windows Machine
  • Click on the Environment Variables button, and it will show you the System Variables and User Variables.
  • You will see the Python path in the User Variable section, as shown in the screenshot below. You can also select the Path row and click on the Edit button to view the Python path in detail.
System path windows machine

How to install Python Packages using Command Prompt?

Though Python has several packages, we will install only numpy, pandas, xlrd, and matplotlib packages responsible for supporting multi-dimensional arrays, data analysis, retrieving data from Microsoft Excel sheet, and producing astonishing quality 2D graphics, respectively.

To install numpy

Python, unfortunately, supports only single-dimensional arrays. However, for those of you who want to work with Multi-dimensional arrays, Python provides the luxury to attain the same by installing a package called numpy. Please follow the steps below to install the same on your machine.

  • Open Command Prompt as administrator
  • Type the command below in the command prompt window as shown in the screenshot below, and it will install the numpy package.
pip install numpy
Install numpy python

I got a warning to upgrade the pip version to 21.1.2 as the pip version on my computer is 21.1.1, as mentioned in the screenshot above. You can also see that this notification also suggests the command you need to enter to remove this warning in future instances. So run the same command in another command prompt as administrator, as shown in the screenshot below, and that should fix this warning once and for all.

pip installation

It is evident from the screenshot above that the 21.1.2 version of pip is installed on the machine. However, you can check the same by running the below command.

pip --version
pip --version command

To install pandas

You might want to install the pandas package for those of you who want to work with data analysis projects. Please find the command below to install the same.

pip install pandas
pip install pandas

To install xlrd

For those of you who want to work with Microsoft Excel sheets, you can make use of the xlrd package. You can install the same using the command below.

pip install xlrd
pip install xlrd

To install matplotlib

If you want to create good 2D graphics, you can install the matplotlib package using the command below.

pip install matplotlib
pip install matplotlib

How to verify the installed packages?

Python allows you to check whether the packages are added to the Python software correctly. Let me show how you can check the same using the command prompt window.

  • Open Command prompt window, type python, and hit enter. This will let you enter the python commands within the Command Prompt Window
  • Type the command below and hit enter. That’s it. You will then see a list of all the modules available on your machine.
help('modules')
python modules

Let’s now write our First Python Program

It is essential to write the first program after installing any programming software. It will not only mark your first step in the programming language but also help you verify whether the installation was successful or not. Let us begin with a simple program to subtract two numbers. Since we already had a look at how to type python code on Command Prompt window, we will now try executing the code in Python’s Command Line Window.

#Let us write our first program of Python to subtract two numbers
x=30
y=10
z=x-y
print("Subtraction Result is ",z)

Executing the program above will produce the output: Subtraction Result is 20. Please refer to the screenshot below.

python subtraction code

How to save Python code in a file via Python IDLE Window?

As a programmer, you might want to type so many lines of code. You can’t just rely on the command line windows to type your whole code in such cases. You need to save the code in a file and run the program file on the command window. This will let you run a code anytime you want without typing the entire code every time. Please follow the instructions to accomplish the same.

  • Open the Python IDLE window from the Start Menu.
  • After the IDLE window is opened, go to File -> New File
  • This will open a new window in which you can enter the entire code. Let’s now enter the code below and save the same in the file. To save the file, hit Ctrl+S.
#first program to divide two numbers
a=10
b=2
c=a/b
print("The division result is ",c)
Save the program

How to run the first Python program file using Command Prompt Window?

Let us now run the Python file that we have saved just now using the Command prompt window. To do the same, follow the steps below.

  • Open Command Prompt
  • Go to the location in which the Python program is saved in CMD.
  • Enter python <filename>.py, and it will display the output. Since I saved the filename as Division, I have to enter the code shared below.
python Division.py
  • Entering the command above will display the output as: The division result is 5.0. Please refer to the screenshot below to view the same.
Python program output

How to get Help on topics on Python?

Knowledge is an ocean, and it takes years to master any talent. A real expert does not stop learning, and that’s why there is a way for those of you who want to get information on any topic in Python and increase your expertise in Python.

Type help() and hit enter in the IDLE Window. When the prompt displays the next line, type topics and hit enter, and you will see an extensive list of topics listed, as shown in the screenshot below. When the command line displays all the topics, enter your desired topic in CAPS. For example, if you want to know about classes, you should enter CLASSES. Make sure that you enter the desired topic in CAPS. Please refer to the screenshot below for more details.

help topics python

In this post, we learned about installing the Python software, verifying the same and its path, installing packages and viewing them, finding help on the topics you want to learn, and running your first python program. As you can see from the content shared above, it is very evident that Python provides more flexibility for a programmer to run code as he/she wishes. We will explore the same in our future posts.

Share with us your experience in running your First Python program in the comments section below. We would love to hear from you.

Source

Scroll to Top