Python is one of the most popular programming languages used for developing many kinds of software. Python is a popular choice for both beginners and expert programmers. Due to its easy-to-learn syntax and powerful libraries, it is loved and adopted by millions of programmers all over the world.
Python can do any task, including Web Development, Data Science, Artificial Intelligence, Automation, or any other General Programming task. Python can be used to build applications for any platform, including Linux, Windows, or Mac. Now Python has also supported building Android applications due to the Kivy library. In today’s article, we will see how to install Python on Linux.
The most significant advantage of Python is its strong support for integration with other languages and tools. People also love the simplicity in which it can be learned in a few days compared to other languages, which takes more time to be learned. Python has many different libraries; we can store data in Python using the SQLite databases in Python, which is a great way to store our application data in Python.
This tutorial will help you set up and install the latest version of Python on Ubuntu and its derivatives, including Linux Mint and elementary OS. If you love Linux, you may also look at the article using Linux shell commands in Python.
Installing Python on Ubuntu and Linux Mint
This tutorial is done on Ubuntu 16.04. It should work on all Ubuntu derivatives, including Linux Mint, Pop!_OS, elementary OS, and more.
Ubuntu, Linux Mint, and many other Linux OS come pre-installed with some version of Python. The only thing you need to verify is if it’s the latest version. To check the current version installed on your computer, launch ‘Terminal’ and type the following command:
You should see a lot of output in the terminal but pay attention to the Python version_number, followed by the date.
Python 3.5.2 (default, Nov 17 2016, 17:05:23)
But as of when this article was written, the Python version available on the official website is Version 3.6.0. It’s always a good idea to have the latest version to get full features.
The easiest way of installing Python in Ubuntu and its derivatives is by using the apt-get command. Of course, there is also a long way to download and install it manually. We shall discuss both methods here.
METHOD 1: Using the apt-get command
STEP 1: Launch Terminal.
STEP 2: Copy and paste the following command and hit enter to add J Fernyhough’s PPA.
sudo add-apt-repository ppa:jonathonf/python-3.6
STEP 3: Update the sources.
sudo apt-get update
STEP 4: Finally, install Python 3.6 using the apt-get command. It will download the installer package and install it. You will have to enter the root password when prompted.
sudo apt-get install python3.6
METHOD 2: Compile from Source Code
If you wish not to add any more PPAs to your computer, you can download the Python source code and compile it.
STEP 1: Before installing Python, it is recommended to install some dependencies. To do that, launch Terminal and copy-paste the following commands in the terminal, and hit enter.
sudo apt-get install build-essential checkinstall
sudo apt-get install libreadline-gplv2-dev libncursesw5-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev
STEP 2: Go to Download Python’s official webpage and download the latest version of Python. You can download the Gzipped source tarball.
STEP 3: Launch Terminal and navigate to the ‘Downloads’ folder or wherever you downloaded the Python .tgz package. Make sure to use the exact file name to extract after -xvf in the below command.
tar -xvf Python-3.6.0.tgz
STEP 4: Now navigate into the extracted directory.
STEP 5: You can now compile the source code. Enter the following command one by one.
Python should now be installed on your computer successfully. After installing Python, you may use one of the best python IDE so you can write code quickly and fast..
This tutorial explains everything about how to install and update Python on a Linux system. You may also want to see our step-by-step guide on installing anaconda in Python. Installing anaconda will let you efficiently manage python packages and maintain a different Python version by creating virtual environments.