Saturday 1 September 2018

Python Tutorial - Python Installation

From wikibooks.org, Python is an interpreted programming language. For those who don't know, a programming language is what you write down(instructions) to tell a computer what to do. However, the computer doesn't read the language directly—there are hundreds of programming languages, and it couldn't understand them all. So, when someone writes a program, they will write it in their language of choice, and then compile it—that is, turn it into lots of 0s and 1s, that the computer can easily and quickly understand. A Windows program that you buy is already compiled for Windows—if you opened the program file up, you'd just get a mass of weird characters and rectangles. Give it a go—find a small Windows program, and open it up in Notepad or Wordpad. See what garbled mess you get. 

Python Installation:

By default Linux users get Python Installed. If you want to confirm the same, just type the following command and see what happens.

python --version

If python is installed you will see something like "Python 2.7" which means you have Python installed and using version 2.7.

However many Linux distributions install version 2.7, but 3.x.x is the newest version and is not backward compatible. So I recommend to upgrade your Python to 3.x.x especially for beginners.

Installing Python 3.x.x: 

sudo apt-get install python 3.3.3

This will install Python 3.3.3, you can confirm the same using

python --version

Now you have two versions of Python one is Python2 and the other is Python3.

By default python2 will be used when you try to execute any python program. So to use python3 we have to alias python3 to python.

To make alias:

In Terminal open vi or any editor the file .bashrc located in your home directory

vi ~/.bashrc

Type “alias python='python3'” without double quotes and save it, then.
source .bashrc 

Thats it now you are all ready to use python3 as default version in your machine.

No comments:

Post a Comment