How do i install a specific version of python in centos 7?

This Blog will help you for installation of up and running with a local Python 3.x programming environment in CentOS 7.x.

The programming language Python was conceived in the late 1980s and its implementation was started in December 1989. Python 3.0 (also called “Python 3000” or “Py3K”) was released on December 3, 2008.
Python 3 is the most current version of the language and is considered to be the future of Python.

Prerequisites
Computer with CentOS 7.x installed with non-root superuser account that is connected to the internet.
Note: Here we have used Amazon Linux AMI [CentOS 7 image]

Step 1 : Set-up installation for Python3.6.2

Note: We can install any of python version 3.x, download it from here. In this blog we are installing python version 3.6.2.

Go to ‘/usr/src’ path

cd /usr/src

Download python version 3.6.2.

sudo wget https://www.python.org/ftp/python/3.6.2/Python-3.6.2.tar.xz

untar downloaded package

sudo tar -xvf Python-3.6.2.tar.xz

Go to ‘Python-3.6.2’ path

cd Python-3.6.2

Installation of gcc compiler and openssl-devel

sudo yum install gccsudo yum install openssl-devel

Configuration of python

sudo ./configure --prefix=/opt/python3sudo make altinstallsudo ln -s /opt/python3/bin/python3.6 /usr/bin/python3.6

Check installation

python3.6 --version

Congratulations!! We have made it Successful…

Creating a Simple Program Hello World Python Program [click here]

The CentOS 7 Linux distribution includes Python 2 by default. However, Python 2 is going to reach EOL on January 1, 2020. While some legacy applications might require access to Python 2 for various reasons, it’s vitally important to kick start new projects in Python 3.

In this tutorial, we are going to take a look at how to get up and running with Python 3 on a CentOS 7 server. Specifically, we will take a look at how to install Python 3 via the CentOS 7 package manager Yum as well as from source.

How do i install a specific version of python in centos 7?

Pre-flight Check

  • These instructions are being performed on a Liquid Web Self-Managed Dedicated CentOS 7 server as the root user.
  • These instructions assume that your server has CentOS release 7.7.
  • We also have an awesome article on managing multiple versions of Python via Anaconda

Yum Installation

In CentOS 7 releases prior to 7.7, it was necessary to make Python 3 available for installation by setting up third-party repositories, such as the IUS repository, because the CentOS base repository did not provide a Python 3 package. Thankfully, as of CentOS 7.7, Python 3 is available in the base package repository!

Step 1: Update the environment

In order to make sure that we are working with the most up to date environment possible in terms of our packages, we can run the following command.

[root@centos7 ~]# yum update -y

Step 2: Install Python 3

Now that the environment is up to date, all we need do to install Python 3 is run the following command.

[root@centos7 ~]# yum install -y python3

That’s it! Python 3 is now installed! Another helpful idea to consider is that PIP, the Python package manager for Python 3, is installed alongside the Python 3 package, so we don’t have to worry about that as an additional installation step.

Verify Installation

In order to ensure that Python 3 is in fact installed and usable, we can drop into a Python 3 shell by running the following command.

[root@centos7 ~]# python3
Python 3.6.8 (default, Aug  7 2019, 17:28:10) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-39)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 

You should see the version of Python 3 installed on your system as well as a change in the command prompt characters.

Source Installation

Installing Python 3 via the Yum package manager is by far the simplest way to get the job done. However, in some cases, you might want to have the most recent version of Python available and that’s where a source installation can come in handy.

Step 1: Setup the Environment

In order to install Python 3 from source, we are going to need to ensure that some prerequisite packages are installed on our system.

[root@centos7 ~]# yum install gcc openssl-devel bzip2-devel libffi-devel -y

Step 2: Download Python

Next, we need to grab the version of Python we want. The following command will pull down the latest stable version of Python 3.8 as of the writing of this article.

[root@centos7 ~]# curl -O https://www.python.org/ftp/python/3.8.1/Python-3.8.1.tgz

Now we need to extract the file.

[root@centos7 ~]# tar -xzf Python-3.8.1.tgz

Step 3: Install Python 3

Now that it’s extracted, let’s change into the resultant directory.

[root@centos7 ~]# cd Python-3.8.1/

Next, we need to prepare to compile Python from source.

[root@centos7 Python-3.8.1]# ./configure --enable-optimizations

Finally, we are going to use the following command to finish off the installation, without replacing the default system Python on our system.

[root@centos7 Python-3.8.1]# make altinstall

Compiling code from source takes a little while, but once that’s finished, we can test out our new Python 3 version by running the following command.

[root@centos7 Python-3.8.1]# python3.8

Much like before when we installed Python 3.6 via Yum, we are dropped into a Python shell that outputs the version we are currently using.

Python 3.8.1 (default, Dec 27 2019, 17:12:30)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-39)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>

Final Thoughts

Python has seen a continuous upward growth trend in the 21st century due to its flexibility in addressing both frontend and backend development goals. It also continues to provide, a strong cross-platform functionality when utilizing server clustering, along with the vast amount of available tools and libraries available that reduces the effort needed to write code and functions. Additionally, it has one of the industries’ strongest support community structures which ensures its continued success.

Because Python provides for the latest technologies with its constant growth and development in the field of Machine Learning and AI, we expect to see these advances continue to increase in the coming years.

How Can We Help?

Liquid Web delivers many of the newest technology private cloud hosting options that can allow you to take advantage of the latest methods and processes to grow your business well into the 21st century and beyond!

Give us a call at 800.580.4985, or open a chat or ticket with us to speak with one of our knowledgeable Solutions or Experienced Hosting advisors to learn how you can apply these tools and techniques today!

How do I install a specific version of Python in Linux?

You can also download latest version in place of specified below..
cd /usr/src sudo wget https://www.python.org/ftp/python/3.5.2/Python-3.5.2.tgz. Now extract the downloaded package..
sudo tar xzf Python-3.5.2.tgz. ... .
cd Python-3.5.2 sudo ./configure sudo make altinstall. ... .
$ python3.5 -V Python 3.5.2..

How do I install a specific version of Python?

Here's the general Pip syntax that you can use to install a specific version of a Python package:.
pip install == ... .
pip install virtualenv. ... .
virtualenv myproject source myproject/bin/activate. ... .
pip install pandas==1.1.1..

How do I get Python 3.7 on CentOS?

Installing Python 3.7 on CentOS 7.
Step 1: System Package Installation. Install below pre-requisites: ... .
Step 2: Downloading Python 3.7. Download python setup in tmp location. ... .
Step 3: Python 3.7 alternate installation. 1 2 3 4 5 6 7. ... .
Step 4: Verifying new python & pip version. 1 2 3 4 5..

How do I install multiple versions of Python on CentOS 7?

Here is the steps that you can follow:.
install virtualenv: sudo yum install virtualenv. ... .
create a virtual env for you app, and precise the python binary you want to use: virtualenv -p /usr/local/bin/python2.7 ~/venv..
Activate it: source ~/venv/bin/activate..
now you are in you virtual env..

What version of Python does CentOS 7 use?

For CentOS 7: Python 3.6. 8 is the latest version available in the CentOS 7 repos. 3.6 reached its EOL in Dec 2021, so you should upgrade ASAP.

How do I upgrade from Python 2 to Python 3 in CentOS?

Procedure.
Update all currently installed packages by running the yum update command. sudo yum update..
To install Python 3, run the dnf command. sudo dnf install python3..
(Optional) To verify that you are using Python 3, run the the python3 -V command. ... .
(Optional) Take a snapshot of your virtual machine..