Alexey Kartsev

Alexey Kartsev

1586115900

How to Install Python 3.8 On Ubuntu 18.04

Python is one of the major programming languages used to develop different types of applications including Web Applications, Desktop Applications, Numeric and Scientific Applications, etc. It soon entered into mainstream programming and majorly popular in data science engineers.

In this tutorial, we will discuss all the steps required to install Python 3 i.e Python 3.8 on the popular Linux distribution Ubuntu. It provides the steps for Ubuntu 18.04 LTS. The steps should be the same for other distributions of Linux.

You might also be interested in Python Cheatsheet to learn or brush up the basics of Python.

Install Python

We can install the Python using the package available at the Ubuntu repositories using the commands as shown below.

# Refresh the packages index
sudo apt update

# Prerequisites
sudo apt install python

# Verify Installation
python --version

# It shows version
Python 2.7.17

# Prerequisites
sudo apt install python3

# Verify Installation
python3 --version

# It shows version
Python 3.6.9

We can see that Python 2.7 and Python 3.6 get installed using the Ubuntu repositories which seems outdated as compared to the most recent version of Python i.e. Python 3.8. You can continue with the next sections to install the most recent version of Python either using the PPA or build from source. Optionally, you may wish to remove Python completely before moving ahead with the next sections using the commands as shown below. Make sure before removing existing Python 2.7 and Python 3.6 since several other packages and programs depend on it. If you are not sure, keep the existing version of Python installed on your system since we can install multiple versions of Python on the same system.

# Uninstall Python - Make sure before going for it
# It will also remove dependent packages including gimp, mysql etc
sudo apt purge remove python
sudo apt purge python3

Install Python using PPA

Install Python 3.8 using the commands as shown below. In several cases, it’s not preferred to install Python using PPA. In such a case, you may follow the next section to install it from the source code.

# Refresh the packages index
sudo apt update

# Install Prerequisites
sudo apt install software-properties-common

# Add deadsnakes PPA to sources
sudo add-apt-repository ppa:deadsnakes/ppa

# Press Enter to continue

# Install Python 3.8
sudo apt install python3.8

The above command will install Python 3.8 at /usr/lib/python3.8. The default version of Python 3 remains installed at /usr/lib/python3. Now verify the installation using the commands as shown below.

# Check Python version
python3.8 --version

# Check the version
Python 3.8.2

You can follow the same steps to install Python 3.6, Python 3.7 using the same PPA. It won’t override the Python 3.6 installed by us using the command sudo apt install python3 and installs it at a separate location i.e. /usr/lib/python3.6. In this way, we can have multiple versions of Python installed on the same system.

# Check Python version
python3.6 --version

# Check the version
Python 3.6.9

# Check Python version
python3.7 --version

# Check the version
Python 3.7.7

Install Python using Source

In this section, we will install Python 3.8 using the source code without using PPA as shown in the previous step.

# Refresh the Packages Index
sudo apt update

# Uninstall Python 3.8 - Installed using PPA in previous step
sudo apt purge python3.8

# Refresh the Packages Index
sudo apt update

# Install Prerequisites
sudo apt install build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev

Now download the latest release of Python 3.8 using wget as shown below.

# Download Python 3.8.2
sudo wget https://www.python.org/ftp/python/3.8.2/Python-3.8.2.tar.xz

Extract the tarball after the download completes.

# Extract
tar -xf Python-3.8.2.tar.xz

Now compile and build the Python from source and install it using the commands as shown below. The make command will take some time to build the binaries from the source files. Also, use altinstall option to avoid overwriting the existing installation.

# Change directory
cd <path to download location>/Python-3.8.2

# Check dependencies
sudo ./configure --enable-optimizations

# Make - Compile and build Python - It will take some time, have a coffee or tea break
sudo make
# OR - specify processor units
sudo make -j 4

# Install Binaries
sudo make altinstall

# Switch active Python
sudo update-alternatives --config python3

# It won't show any option for python3

# Verify Installation
python3 --version

# It shows version
Python 3.6.9

# Verify Installation
python3.8 --version

# It shows version
Python 3.8.2

The above commands will install the most recent version of Python 3.8, but won’t enable it to be used using the command python3 from the console as shown above. The next section explains the steps to access Python 3.8 from the command line using python3.

Switch Installation (Optional)

If you have installed multiple minor versions of Python i.e. python3.6, python3.7, python3.8, etc, you can use the below mentioned commands to activate one installation at a time to use python3 instead of using python3.6, python3.7, or python3.8 on the command line. We can also switch to other versions by configuring the active command.

Notes: Configuring python3 to use the python installed using the PPA or source will disable the python3 installed using the command sudo apt install python3. You may use a different command instead of python3 to avoid any system discrepancy.

# Add python3 choice using python3.6
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6 1

# Add python3 choice using python3.8
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.8 2

# Verify Installation
python3 --version

# It shows version
Python 3.8.2

Since we have provided the choices to switch between multiple versions of python3, we can switch the active version using the command as shown below.

# Switch active Python
sudo update-alternatives --config python3

I have used my local installation of Python 3.8 as shown in Fig 1.

Switch Python
Fig 1

As soon as we enable the command python3 to refer Python 3.8 installed by us using the source code, the terminal stops working. So make sure to fix the terminal before closing it as shown below.

# Update Terminal Script
sudo nano /usr/bin/gnome-terminal

# Replace the first line to use python3.6
#! /usr/bin/python3.6

Apart from breaking the terminal, you will also get an error of missing apt_pkg while running the command sudo apt-get update as shown below.

ubuntu@ubuntu:~$ sudo apt-get update
Hit:1 http://ppa.launchpad.net/deadsnakes/ppa/ubuntu bionic InRelease                             
Get:2 http://security.ubuntu.com/ubuntu bionic-security InRelease [88.7 kB]                                           
Hit:3 http://us.archive.ubuntu.com/ubuntu bionic InRelease                                                 
Get:4 http://us.archive.ubuntu.com/ubuntu bionic-updates InRelease [88.7 kB]        
Get:5 http://us.archive.ubuntu.com/ubuntu bionic-backports InRelease [74.6 kB]
Fetched 252 kB in 4s (62.9 kB/s)   
Traceback (most recent call last):
  File "/usr/lib/cnf-update-db", line 8, in <module>
    from CommandNotFound.db.creator import DbCreator
  File "/usr/lib/python3/dist-packages/CommandNotFound/db/creator.py", line 11, in <module>
    import apt_pkg
ModuleNotFoundError: No module named 'apt_pkg'
Reading package lists... Done
E: Problem executing scripts APT::Update::Post-Invoke-Success 'if /usr/bin/test -w /var/lib/command-not-found/ -a -e /usr/lib/cnf-update-db; then /usr/lib/cnf-update-db > /dev/null; fi'
E: Sub-process returned an error code

The apt_pkg can be fixed using the commands as shown below.

# Navigate to default Python 3 
cd /usr/lib/python3/dist-packages/

# Fix apt_pkg
sudo ln -s apt_pkg.cpython-36m-x86_64-linux-gnu.so apt_pkg.so

You can also fallback and fix the python3 command as shown below.

# Remove python3 link
sudo rm /usr/bin/python3

# Fallback to python3.6
sudo ln -s /usr/bin/python3.6 /usr/bin/python3

# Update Terminal Script
sudo nano /usr/bin/gnome-terminal

# Replace the first line to use python3
#! /usr/bin/python3

You can use some other short name instead of python3 or simply use python3.8 to access the most recent version of Python(installed from source) from the terminal.

This is how we can install the latest Python on Ubuntu 18.04 LTS. We have also checked how to install and switch among the multiple versions of Python installed on the same system.

Hello World

In this section, we will write our first program in Python using the nano editor.

>sudo mkdir -p /data/programs/python
>cd /data/programs/python
>sudo nano helloworld.py

Now write the first program in Python as shown below, save the program by pressing Ctrl + O and hit Enter and exit the editor by pressing Ctrl + X.

# Print Hello World
print("Hello World !!")

Use the python3 installed by us to execute the program as shown below.

# Execute the program
python3 helloworld.py
# OR
python3.8 helloworld.py

# Program output
Hello World !!

These are the basic steps to write and execute Python programs.

Summary

This tutorial provided the steps to install Python 3.8 on Ubuntu 18.04 LTS and showed the process to manage multiple installations of Python on the same system.

#python #ubuntu #web-development

What is GEEK

Buddha Community

How to Install Python 3.8 On Ubuntu 18.04

How to Install Pyenv on Ubuntu 18.04

What is Pyenv?
Pyenv is a fantastic tool for installing and managing multiple Python versions. It enables a developer to quickly gain access to newer versions of Python and keeps the system clean and free of unnecessary package bloat. It also offers the ability to quickly switch from one version of Python to another, as well as specify the version of Python a given project uses and can automatically switch to that version. This tutorial covers how to install pyenv on Ubuntu 18.04.

#tutorials #apt #debian #environment #git #github #linux #package #package management #package manager #personal package archive #ppa #pyenv #python #python 3 #python support #python-pip #repository #smb #software #source install #ubuntu #ubuntu 18.04 #venv #virtualenv #web application development

Ray  Patel

Ray Patel

1619518440

top 30 Python Tips and Tricks for Beginners

Welcome to my Blog , In this article, you are going to learn the top 10 python tips and tricks.

1) swap two numbers.

2) Reversing a string in Python.

3) Create a single string from all the elements in list.

4) Chaining Of Comparison Operators.

5) Print The File Path Of Imported Modules.

6) Return Multiple Values From Functions.

7) Find The Most Frequent Value In A List.

8) Check The Memory Usage Of An Object.

#python #python hacks tricks #python learning tips #python programming tricks #python tips #python tips and tricks #python tips and tricks advanced #python tips and tricks for beginners #python tips tricks and techniques #python tutorial #tips and tricks in python #tips to learn python #top 30 python tips and tricks for beginners

Chet  Lubowitz

Chet Lubowitz

1595429220

How to Install Microsoft Teams on Ubuntu 20.04

Microsoft Teams is a communication platform used for Chat, Calling, Meetings, and Collaboration. Generally, it is used by companies and individuals working on projects. However, Microsoft Teams is available for macOS, Windows, and Linux operating systems available now.

In this tutorial, we will show you how to install Microsoft Teams on Ubuntu 20.04 machine. By default, Microsoft Teams package is not available in the Ubuntu default repository. However we will show you 2 methods to install Teams by downloading the Debian package from their official website, or by adding the Microsoft repository.

Install Microsoft Teams on Ubuntu 20.04

1./ Install Microsoft Teams using Debian installer file

01- First, navigate to teams app downloads page and grab the Debian binary installer. You can simply obtain the URL and pull the binary using wget;

$ VERSION=1.3.00.5153
$ wget https://packages.microsoft.com/repos/ms-teams/pool/main/t/teams/teams_${VERSION}_amd64.deb

#linux #ubuntu #install microsoft teams on ubuntu #install teams ubuntu #microsoft teams #teams #teams download ubuntu #teams install ubuntu #ubuntu install microsoft teams #uninstall teams ubuntu

Servo Node

Servo Node

1626801695

Install VirtualBox in Ubuntu 21.04/20.04/18.04 › Servo Node

VirtualBox is a widely known and open-source tool offered by Oracle. It’s a cross platform virtualization application that can be installed on any system that allows users to run a number of guest operating systems on single machine over a virtual system.

Means, with the usage of VirtualBox on your system, you can easily install many operating systems and can run them simultaneously which can be helpful to develop, demonstrate, deploy and test applications on a single machine.

How to install VirtualBox On Ubuntu 18.04, 20.04 and 21.04?

Since the virtualization system offered by Oracle is available for cross platforms, even Ubuntu users can install the app and take its benefits. In order to install VirtualBox in Ubuntu variants, there’s a number of approaches that can be helpful.

Installing using default repository

sudo apt install virtualbox

Install using official DEB package

Visit the Virtualbox download page and download DEB package in your machine, and run the following command to install the package using ATP command.

sudo apt install ./virtualbox-6.1_6.1.22-144080_Ubuntu_bionic_amd64.deb

for more approaches and information, Read Here

#install virtual box on ubuntu #install virtual box on ubuntu 18.04 #install virtual box on ubuntu 20.04 #install virtual box on ubuntu21.04

Ray  Patel

Ray Patel

1619510796

Lambda, Map, Filter functions in python

Welcome to my Blog, In this article, we will learn python lambda function, Map function, and filter function.

Lambda function in python: Lambda is a one line anonymous function and lambda takes any number of arguments but can only have one expression and python lambda syntax is

Syntax: x = lambda arguments : expression

Now i will show you some python lambda function examples:

#python #anonymous function python #filter function in python #lambda #lambda python 3 #map python #python filter #python filter lambda #python lambda #python lambda examples #python map