Python is one of the most popular programming languages in the world. Installing Python on your computer and writing your first program is fairly simple. This article overviews the steps.
Installing the Python Interpreter
In computer science, an interpreter is a computer program that executes instructions in a specific programming language. The Python interpreter takes the code written in Python, compiles it into Python’s byte code, and executes the Python byte code on a virtual machine. Python’s byte code (similar to Java byte code and many other programming languages that use a virtual machine) is very similar to machine code. However, unlike machine code, it doesn’t run directly on the computer. It runs on a virtual computer created using a virtual machine. The Python interpreter includes the required utilities for developing and running code in Python, and includes the virtual machine itself.
The first step would be downloading and installing the Python interpreter. You can find it available for free download at https://www.python.org/downloads. Make sure you download the version that is suitable for your computer operating system.
Once the download completes, just double click it and goes through the steps. Make sure you accept the license agreement and provide the required access the installer asks.
Installing Integrated Development Environment
Once the Python interpreter is installed we can start writing our code in Python using a simple text editor and use the python utility for executing our program. However, doing so requires us to use the terminal. Most people are not familiar with the terminal, and many others don’t find it comfortable. For that reason, our advice is to install an integrated development environment (IDE). One popular option is PyCharm. Another popular option is VS Code. These are the two most popular Python IDEs. Based on my experience teaching Python programming, I find the PyCharm IDE more friendly. You can download the community free version of PyCharm at https://www.jetbrains.com/pycharm/download.
Once the download completes, double-click the downloaded file and go through the installation steps. Assuming the Python interpreter was already installed, the installation process of PyCharm will identify the location of the Python interpreter and will configure PyCharm accordingly.
Writing The First Program in Python
In order to verify that Python was installed correctly we should code a simple program and execute it. When executing PyCharm for the first time, most likely that you will get a screen that doesn’t show previous projects.
The next step would be pressing the ‘New Project’ button and fill in the details of the new project you want to create. You can specify the name of the project and its location. You can also specify that you want to create a new environment using the virtualenv utility. This is the window in which you can also specify the Python interpreter you want the new project to use. Most likely that you will see the Python interpreter you have just installed. You can specify that you want a main.py file to be created. Files with the ‘py’ extension are files that include code in Python.
The next step would be to execute the code in Python you can find in the main.py file. Just open the main.py file, right-click with your mouse pointing at the tab window where main.py is opened, and select Run ‘main’ from the opened context menu.
You will get to see the code running and you will get to see its output shown on the bottom of the window.
In line #7 you can find a definition for a function. We define a function using the def keyword. It is a function that takes a string and prints it to the console. The print function (in line #9) prints to the console whatever is passed over. The if statement (in line #13) just verifies that the code in this file is executed directly and not indirectly due to import another module does to this file.
If you are new to programming, you can write another simple program, that includes one single line that prints hello to the screen, and execute it the way we have just explained.
If you want to learn Python we recommend you to check out our Introduction to Programming with Python online course on Udemy. It was developed in English. If you happen to know Hebrew, check out our תכנות בפייתון course at life michael academy, and our premium course Python Programming. In addition, we recommend you to check out our other Python related courses and seminars.