Installing python is like installing any other software. But, you should pick the compatible version of Python. The python installation tutorial begins with “Install Python on Windows” followed by “Install Python on Linux” and “Install Python on Mac”. Finally, in the end, you’ll learn how to install Python on IOS and Android platforms.
If you are completely new to python and wanted to deep dive in the python journey then check here to understand python is for you or not.
Python 2 has been downgraded since 1 January 2020.
We would install and code in python 3.x version( as of now 3.8) in this series.
Let’s begin our “Install python on any platform” with Python Installation on Windows.
Microsoft Windows, the most popular operating system don’t have pre-installed Python. But, you can install python on windows like any other application or software. The most stable python release is 3.8.3.
Python 3.8.3 doesn’t work on previous version of Windows (i.e. XP or earlier).
Downloading python-3.8.5.exe file
Step 1 – Visit the official Python download page here. Hover, cursor over the download menu option and then click on the Python 3.8.5 button to begin download.
Important point: Hover over the Download section and click on Windows.
Step 2 – A new page will open which contains all the binary releases of python 2 and python 3. Select python versions (as of now it is python 3.8.3).
Step 3:- Click on (Download Windows x86-64 executable installer (26 MB of size)).
Installation
Step 1:- Click on the executable installer and grant administrative access to the program. A window like this or similar will appear.
Step 2:- Choose the Customize installation if you want to change something otherwise follow the instruction.
Check in the box which says Add python to the Path.
Step 3:- It will take 2 -3 minutes to install and a screen indicating installation successful will appear. If any error occurred you can write to me in the comment section,I will definitely try to help you.
Setup and Verification
Step 1 – You can verify the python installation and its version by using following command.
Step 2 – Run your first python script
Type python on command line and press enter. A python interpreter will open and now you can write python script in it. Refer following python interpreter screen shot. Type exit() to close the python interpreter.
- Write python script in any text editor like Notepad and save it with .py extension and run in cmd using command.
python filename.py
First change the directory to the directory where you saved your file.
In contrast to Microsoft Windows, Python comes pre-installed in most Linux distributions. Linux system would have Python 2 by default. Moreover, you need to upgrade to Python 3.
The following terminal commands can be used to confirm the installation of Python on the Linux system. If you don’t get any command result, then you need to download and install python on linux machine.
$ python --version
Python 2.7.17
$ python3 --version
Python 3.6.9
1.Ubuntu
Open the terminal using Ctrl + Alt + T .
Step 1:- First update the repositories by using the command.
$ sudo apt-get update
Step 2:- Add Deadsnakes Repositories.
$ sudo apt-get install software-proprerties-common
$ sudo add-apt-repository ppa:deadsnakes/ppa
Step 3:- Perform Step 1
Step 4:- Install Python
$ sudo apt-get install python3.8
Step 5:- Now, run the below command
$ python --version
Change default python version
- The above command may show you python 2.x version as it is default python version. To change it ,follow the commands.
$ sudo nano ~/.bashrc
- At the end of the file, append the following line.
alias python=python3.8
- Save the file and run the below command in terminal.
$ sudo source ~/.bashrc
$ python --version
It will show you the current version as of now python 3.8.3
2. Compiling from Source
Downloading
Step 1:- Visit the official python download page here .
Step 2:- Hover over download section and click on Source Code
Step 3:- Download Gzipped source Tarball for the latest python 3.x release.
Preparation
Choose apt-get (like debian,ubuntu,mint) or yum( like centOS ) as per your linux distribution.
Step 1:- Update packages and repositories.
$ sudo apt-get update
$ sudo apt-get upgrade
Step 2:- Download necessary tools
# For apt based ditros
$ sudo apt-get install -y make build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev libncursesw5-dev xz-utils tk-dev
# For yum based distros
$ sudo yum -y groupinstall development
$ sudo yum -y install zlib-devel
Building from scratch
Step 1 – Extract the downloaded tar file.
$ tar xvf filename.tgz
$ cd filename
Step 2 – Prepare the build.
$ ./configure --enable
-optimizations --with-ensurepip=install
Step 3 – Start Building
$ make -j 8
Step 4 – Install the latest version python
$ sudo make altinstall
If you don’t use altinstall , it will overwrite the system preinstalled version.
Step 5:- Step 5:- Check if everything goes right
$ python3 --version