The latest stable version of the Python programming language for Ubuntu 19.04 Linux to install while writing this tutorial article was 3.7.
For those don’t know about the Python, it is a computer programming language. An object-oriented dynamically typed language originally designed to write automated scripts (shells) that are increasingly being used for stand-alone, large-scale project development as versions are continually updated and new language features are added.
For Ubuntu 19.04 or 18.04 three Python versions are available by default that are:
- python3 # version 3.7.3-1,
- python # version 2.7.16-1
- python-minimal # version 2.7.16-1
Note: Ubuntu 19 or 18 by default has Python 3.7.3, in case you want to change the version or don’t have pre-install Python then follow the below steps. This tutorial is also applicable for Linux Mint, Debian, Elementary OS and other same streams.
How to Install Python 3.4.4 on Ubuntu: Some package will suits with some particular dependency packages. Here we have python 3.4.4, which. If you are using Ubuntu 16.10 or newer, then you can easily install Python 3.6 with the following commands: $ sudo apt-get update $ sudo apt-get install python3.6 If you’re using another version of Ubuntu (e.g. The latest LTS release) or you want to use a more current Python, we recommend using the deadsnakes PPA to install Python 3.8.
Step 1: Open Command terminal
To install Python on Ubuntu, go to Applications and search to open the command terminal. Alternatively, you can simply use the Keyboard shotcut i.e CTRL+Alt+T.
Step 2: Update the system
Before installing or removing any packages, once run the update command:
Step 3: Install Python on Ubuntu
If you don’t have the latest version on your Ubuntu 19.04 i.e Python3 then use the below command to install:
For those want to install some previous version of Python on their Ubuntu Linux OS they can use the below commands:
For Python 2.7.x version
For Python minimal version of 2.7
Use Apt repository to install Python
To install any previous Python version such as Python 2.3 – Python 2.6, Python 3.1 – Python3.4, Python 3.6 – Python3.7… We can simply use Deadsnake repository, here is the command for that:
After adding the repo use Python installation command along with the version you want to install, for example:
Switch between multiple Python versions
Python 3.4 Windows Installer
In case, your Ubuntu or Debian system has installed with multiple Python versions and you want to set some particular version as default. Then you can switch among them.
We have four Python versions on our system, so first, we set priority for them:
Now, use the below command every time you want to set some particular version as default:
Install Python using Source file on Ubuntu (optional)
If you are looking for some old version or some particular version of Python to be installed on Ubuntu or Linux Mint then you can simply compile it from the source. You can get archives each and every version of Python from its official website.
Here is the Python Source file download page.
For showing you how to compile any version of Python from its source on Ubuntu 19.04/18.04/1604 or Linux Minit or Debian, here we are downloading Python 3.4 version compressed source Tarball file.
To download Python Source file we use WGETcommand:
Right click on the Python Tarball file given on the website and copy the link and after that use it with wget in your terminal:
For example, we have copied the link of Python 3.4 tarball file…
Extract Tarball File
After downloading type:
and then see the name of the downloaded file, it will be like this Python-x.x.x.tar.zx
x.x.x will be the version as in our case it was 3.4.0, thus our filename was Python-3.4.0.tar.xz
Use the below command to extract tarball file:
tar -xf {file name}
Navigate to the folder and run configure script
Install Python 3.4 Ubuntu Command
After extracting your downloaded Python folder, first, switch to that directory for that
cd {directory name}
In our case:
As you inside the directory, run the Configure script to check all the required dependencies before finally compiling the source:
Note: –enable-optimizations option will optimize the Python for your system.
Compile Python on Ubuntu
To compile python you can use the command make, however, to do it as per your computer CPU core resources, we use the flag -j with it. For that first, you should know about your PC cores.
To find PC cores type command
Now use the core number with -j flag. Thus the final command will be:
Command Reference
2 is the number of core we have on our system.
Finally, Install Python from compiled source
Note: In the below command we are not using standard installation command to install program from source i.e make install, becuase it will override your default pre-installed python version. Thus we use it with alt.
Tutorial
Introduction
Python is a flexible and versatile programming language, with strengths in scripting, automation, data analysis, machine learning, and back-end development.
This tutorial will walk you through installing Python and setting up a programming environment on an Ubuntu 18.04 server. For a more detailed version of this tutorial, with better explanations of each step, please refer to How To Install Python 3 and Set Up a Programming Environment on an Ubuntu 18.04 Server.
Step 1 — Update and Upgrade
Logged into your Ubuntu 18.04 server as a sudo non-root user, first update and upgrade your system to ensure that your shipped version of Python 3 is up-to-date.
Confirm installation if prompted to do so.
Step 2 — Check Version of Python
Check which version of Python 3 is installed by typing:
You’ll receive output similar to the following, depending on when you have updated your system.
Step 3 — Install pip
To manage software packages for Python, install pip, a tool that will install and manage libraries or modules to use in your projects.
Python packages can be installed by typing:
Here, package_name
can refer to any Python package or library, such as Django for web development or NumPy for scientific computing. So if you would like to install NumPy, you can do so with the command pip3 install numpy
.
Step 4 — Install Additional Tools
There are a few more packages and development tools to install to ensure that we have a robust set-up for our programming environment:
Step 5 — Install venv
Virtual environments enable you to have an isolated space on your server for Python projects. We’ll use venv, part of the standard Python 3 library, which we can install by typing:
Step 6 — Create a Virtual Environment
You can create a new environment with the pyvenv
command. Here, we’ll call our new environment my_env
, but you can call yours whatever you want.
Step 7 — Activate Virtual Environment
Activate the environment using the command below, where my_env
is the name of your programming environment.
Your command prompt will now be prefixed with the name of your environment:
Step 8 — Test Virtual Environment
Open the Python interpreter:
Note that within the Python 3 virtual environment, you can use the command python
instead of python3
, and pip
instead of pip3
.
You’ll know you’re in the interpreter when you receive the following output:
Now, use the print()
function to create the traditional Hello, World program:
Step 9 — Deactivate Virtual Environment
Quit the Python interpreter:
Then exit the virtual environment:
Further Reading
Here are links to more detailed tutorials that are related to this guide: