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:
python3 -V
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.
cd Downloads
tar -xvf Python-3.6.0.tgz
STEP 4: Now navigate into the extracted directory.
cd Python-3.6.0
STEP 5: You can now compile the source code. Enter the following command one by one.
./configure
make
make install
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..
Conclusion
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.
10 comments
Hi Kiran,
I’m not able to install python3.6 in linuxmint as i’m getting failures like E: Some index files failed to download. They have been ignored, or old ones used instead.I tried below steps also
mint@mint ~ $ sudo cp /etc/apt/sources.list ~/
mint@mint ~ $ sudo apt-get update
but results were same,not able to install python3.6 on linuxmint 14.04.
Could you please suggest to complete installation?
Thanks in advance.
Thanks Kiran,
Python 3.7.4 is installed on Linuxmint 19 with your guidance.
I got the following error after “make install”:
——ModuleNotFoundError: No module named ‘_ctypes’——
Visited, https://github.com/pyenv/pyenv/issues/1183 and installation succeeded after running: sudo apt-get install libffi-dev
Thanks a lot
Nishant
Thanks Nishant nice addition
Thank you Kiran. Could not help thanking you. I have Linux Mint 19.3 installed on my Compaq laptop where Python 2.7 and 3.6 were already installed. I checked the Python.org website and found Python 3.8.1. Downloaded the latest and following your instructions (make, make install etc.) successfully updated Python 3.6 to 3.8.1. Only thing…’make’ ran ok but ‘make install’ needed sudo to run.
Thanks a lot.
Thanks was stuck at make install
Installing python 3.8 on linux mint cinnamon 19.3 cause all many libraries also in python 2.7 not to work
Hi
Thanks for the guidance. Successfully updated python on my linux mint cinnamon 19.3.
Hi, when I got up to the end of the install it said it was successfully installed but is nowhere to be found. There is aslo a warning message:
WARNING: The directory ‘/home/zac/.cache/pip/http’ or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo’s -H flag.
Do you think anyone could help with this?
The two versions of Python, 3.6 and 2.7 are required for Linux Mint 19.3 to function. Altering and/or replacing them is probably a very bad idea. Adding another version for use is not, and can run along side the other two. To use it you’ll simply address it by its version.
The installation method provide here is incomplete and dangerous to your system if you try to ‘fix’ it by using what you think you know.
The end install must be given the directive ‘make altinstall’ …
Not ‘make install’.
And the entire process aught to be sudo’d.
Unpack your python tarbal under /usr/local/src
and work from there.
Tnx, it did help me to install Python on my linux mint. Keep up the good work.