Start with python | Installation On Windows and Linux.
Now we know some basics about the python programming language. In this tutorial, we will start with basic practical python learning. The tutorial is designed in such a way that even a person with no programming knowledge can also start learning.
The first step is to install and set up a programming environment. You will learn how to set up the environment on Windows and Linux. The former will be a GUI based interface while the later will be via Linux console with the command line.
You can download python from here.
How to Install and use Python on Windows?
You need to download the python installer. After double click on the installer, you will see the screen on right. It has two options one is installed now and another is Customize installation. The first option is for default installation options and installation path. While if you use another option you can customize packages and the installation path. But for simplicity, we will click on the Install now option.
After a successful installation, you will see the below screen. To start the python console you need to type python in the start search box and click on python.
The black console appears in the interactive programming environment. Here you can write the python code and execute. For example, if you want to add two numbers, print Hello World, etc.
Adding two numbers example – Type 3 +5 after >>> and enter you will see the output 8. Here 3 and 5 are the operands and + is an operator.
Python 3.8.5 (tags/v3.8.5:580fbb0, Jul 20 2020, 15:43:08) [MSC v.1926 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> >>> >>> 3+ 5 8 >>>
Print “Hello World” using the print function.
>>> print("Hello World") Hello World >>>
How to run a python program from a file?
Till now we have successfully executed a few lines of code in interactive mode. Where we write code on prompt and get output. But this is not the case with real software development. The programmer writes instructions in a file and passes it to the interpreter as input.
Lest write the print(“Hello World”) in a text file using a text editor and save the file with .py extension. In our example the file name is HelloWorld.py. To run, on cmd type “
D:\Python Examples>py HelloWorld.py Hello World D:\Python Examples>
Alternatively, you can also use an IDE for software development.
How to Install on Linux?
Linux is another popular operating system. It is mainly used to deploy heavy applications on servers. For demonstration, e are using CentOs7 with 64 bit. The Linux machine is connected to the internet so that we can install any package or rpm using yum. All operations will be using console by doing ssh to the machine using putty.
Check if Python is installed?
# python --version Python 2.7.5 #
Yes, we have already installed python. If not so do not worry you can use the following command to install python.
# sudo yum install python
Create a HelloWord.py file using the VIM editor. Write line print(“Hello World – Linux”); . Save and close the file. The execution following.
# python HelloWord.py Hello World - Linux #
We have learned how to set up the basic python environment to start programming. There could other packages are needed while working with python e.g
setuptools and PIP. These we will cover in another tutorial with details. Here covering may create a complexity to understand.