How to install python to linux
How to install python to linux
How to install Python on Linux?
Before we start with how to install Python3 on Linux, let’s first go through the basic introduction to Python. Python is a widely-used general-purpose, high-level programming language. Python is a programming language that lets you work quickly and integrate systems more efficiently. There are two major Python versions- Python 2 and Python 3. Both are quite different.
Getting started with Python
Python is a lot easier to code and learn. Python programs can be written on any plain text editor like notepad, notepad++, or anything of that sort. One can also use an online IDE for writing Python codes or can even install one on their system to make it more feasible to write these codes because IDEs provide a lot of features like intuitive code editor, debugger, compiler, etc.
To begin with, writing Python Codes and performing various intriguing and useful operations, one must have Python installed on their System. This can be done by following the step by step instructions provided below:
What if Python already exists? Let’s check
Most of the Linux OS has Python pre-installed. To check if your device is pre-installed with Python or not, just go to terminal using Ctrl+Alt+T
Now run the following command:
For Python2
For Python3.x
If Python is already installed, it will generate a message with the Python version available.
Download and Install Python:
Before starting with the installation process, you need to download it. For that all versions of Python for Linux are available on python.org.
Download the required version and follow the further instructions for the installation process.
Beginning the installation.
For almost every Linux system, the following command could be used to install Python directly:
To verify the installation enter the following commands in your Terminal.
Let’s consider a simple Hello World Program.
2. Using Python on Unix platformsВ¶
2.1. Getting and installing the latest version of PythonВ¶
2.1.1. On LinuxВ¶
Python comes preinstalled on most Linux distributions, and is available as a package on all others. However there are certain features you might want to use that are not available on your distro’s package. You can easily compile the latest version of Python from source.
In the event that Python doesn’t come preinstalled and isn’t in the repositories as well, you can easily make packages for your own distro. Have a look at the following links:
for Debian users
for OpenSuse users
for Fedora users
for Slackware users
2.1.2. On FreeBSD and OpenBSDВ¶
FreeBSD users, to add the package use:
OpenBSD users, to add the package use:
For example i386 users get the 2.5.1 version of Python using:
2.1.3. On OpenSolarisВ¶
2.2. Building PythonВ¶
If you want to compile CPython yourself, first thing you should do is get the source. You can download either the latest release’s source or just grab a fresh clone. (If you want to contribute patches, you will need a clone.)
The build process consists of the usual commands:
Configuration options and caveats for specific Unix platforms are extensively documented in the README.rst file in the root of the Python source tree.
2.3. Python-related paths and filesВ¶
Recommended location of the interpreter.
Recommended locations of the directories containing the standard modules.
Recommended locations of the directories containing the include files needed for developing Python extensions and embedding the interpreter.
2.4. MiscellaneousВ¶
To easily use Python scripts on Unix, you need to make them executable, e.g. with
and put an appropriate Shebang line at the top of the script. A good choice is usually
To use shell commands in your Python scripts, look at the subprocess module.
2.5. Custom OpenSSLВ¶
Build Python with custom OpenSSL (see the configure –with-openssl and –with-openssl-rpath options)
Patch releases of OpenSSL have a backwards compatible ABI. You don’t need to recompile Python to update OpenSSL. It’s sufficient to replace the custom OpenSSL installation with a newer version.
How to Download and Install Python Latest Version on Linux?
Python is a widely-used general-purpose, high-level programming language. This article will serve as a complete tutorial on How to download and install Python latest version on Linux Operating Systems.
On every Linux system including following OS,
You will find Python already installed. You can check it using the following commands from the terminal
To check latest version of python 2.x.x :
To check latest version of python 3.x.x :
Clearly it won’t be the latest version of python. There can be multiple methods to install python on a linux base system and it all depends on your linux system.
For almost every Linux system, the following commands would work definitely.
Download and install Python Latest Version on Linux
To install latest version from source code of Python follow below steps
Download Python Latest Version from python.org
You can do all the above steps in a single command
Install Python 3.7.4 Latest Version on Linux
For installing Python successfully on Linux, Enter Following command to get the prerequisites and other source files
Now we are all ready to unpack the file downloaded from the python official website’
Move to downloads directory using cd downloads in terminal
and then enter following commands
Bingo. The latest version of Python language is installed on your Linux system. You can confirm it using below command.
How to set Python 3 as the default version in Linux?
Now any code executed will automatically get python3 as default version.
Installing Python 3 on Linux¶
This document describes how to install Python 3.6 or 3.8 on Ubuntu Linux machines.
To see which version of Python 3 you have installed, open a command prompt and run
If you are using Ubuntu 16.10 or newer, then you can easily install Python 3.6 with the following commands:
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:
If you are using other Linux distribution, chances are you already have Python 3 pre-installed as well. If not, use your distribution’s package manager. For example on Fedora, you would use dnf :
Note that if the version of the python3 package is not recent enough for you, there may be ways of installing more recent versions as well, depending on you distribution. For example installing the python3.9 package on Fedora 32 to get Python 3.9. If you are a Fedora user, you might want to read about multiple Python versions available in Fedora.
Working with Python 3¶
At this point, you may have system Python 2.7 available as well.
This might launch the Python 2 interpreter.
This will always launch the Python 3 interpreter.
Setuptools & Pip¶
The two most crucial third-party Python packages are setuptools and pip.
Once installed, you can download, install and uninstall any compliant Python software product with a single command. It also enables you to add this network installation capability to your own Python software with very little work.
Python 2.7.9 and later (on the python2 series), and Python 3.4 and later include pip by default.
To see if pip is installed, open a command prompt and run
Note that on some Linux distributions including Ubuntu and Fedora the pip command is meant for Python 2, while the pip3 command is meant for Python 3.
However, when using virtual environments (described below), you don’t need to care about that.
Pipenv & Virtual Environments¶
The next step is to install Pipenv, so you can install dependencies and manage virtual environments.
A Virtual Environment is a tool to keep the dependencies required by different projects in separate places, by creating virtual Python environments for them. It solves the “Project X depends on version 1.x but, Project Y needs 4.x” dilemma, and keeps your global site-packages directory clean and manageable.
For example, you can work on a project which requires Django 1.10 while also maintaining a project which requires Django 1.8.
This page is a remixed version of another guide, which is available under the same license.
This opinionated guide exists to provide both novice and expert Python developers a best practice handbook to the installation, configuration, and usage of Python on a daily basis.
O’Reilly Book
This guide is now available in tangible book form!
All proceeds are being directly donated to the DjangoGirls organization.
How to install Python on Linux
Alex Sanchez. CC BY-SA 4.0.
Python is now the most popular, most used programming language. Python’s simple syntax and low learning curve make it the ultimate choice for beginners as well as professional developers. Python is also a very versatile programming language. It’s used nearly everywhere—from web development to artificial intelligence—really anywhere other than mobile development.
If you’re using Python, there’s a good chance you’re a developer (or want to become one), and Linux is a great platform for creating software. But when you’re working with Python every day, you sometimes want to stay up to date with the very latest version. You may not want to replace the default install of Python on your system just to test drive the latest one, so this article explains how to install the latest version of Python 3 on Linux without replacing the version provided by your distribution.
Step-by-step installation instructions
Step 1: First, install development packages required to build Python.
On Debian:
On Fedora:
Step 2: Download the stable latest release of Python 3
Visit the official Python website and download the latest version of Python 3. After the download is complete, you hav a .tar.xz archive file (a «tarball») containing the source code of Python.
Step 3: Extract the tarball
Once the download is complete, extract the tarball by either using the extractor application of your choice or the Linux tar command, for example:
Step 4: Configure the script
Once the Python tarball has been extracted, navigate to the configure script and execute it in your Linux terminal with:
The configuration may take some time. Wait until it is successfully finishes before proceeding.
Step 5: Start the build process
If you already have a version of Python installed on your system and you want to install the new version alongside it, use this command:
The build process may take some time.
If you want to replace your current version of Python with this new version, you should uninstall your current Python package using your package manager (such as apt or dnf) and then install:
However, it’s generally preferable to install software as a package (such as a .deb or .rpm file) so your system can track and update it for you. Because this article assumes the latest Python isn’t yet packaged yet, though, you probably don’t have that option. In that case, you can either install Python with altinstall as suggested, or rebuild an existing Python package using the latest source code. That’s an advanced topic and specific to your distribution, so it’s out of scope for this article.
Step 6: Verify the installation
If you haven’t encountered any errors, the latest Python is now installed on your Linux system. To verify it, write one of these commands in your terminal:
If the output says Python 3.x, Python 3 has been successfully installed.