Ten years ago, the developers of the Python programming language decided to clean things up and release a backward-incompatible version, Python 3. They initially underestimated the impact of the changes, and the popularity of the language. Still, in the last decade, the vast majority of community projects has migrated to the new version, and major projects are now dropping support for Python 2.
In Red Hat Enterprise Linux 8, Python 3.6 is the default. But Python 2 remains available in RHEL 8.
Using Python in RHEL 8
To install Python, type
yum install python3.
To run Python, type
python3.
If that doesn’t work for you, or you need more details, read on!
Python 3
In RHEL 8, Python 3.6 is the default, fully supported version of Python. It is not always installed, however. Similarly to any other available tool, use
yum install python3 to get it.
Add-on package names generally have the
python3 prefix. Use yum install python3-requests to install the popular library for making HTTP connections.Python 2
Not all existing software is ready to run on Python 3. And that’s OK! RHEL 8 still contains the Python 2 stack, which can be installed in parallel with Python 3. Get it using
yum install python2, and run with python2.Why not just “Python”?
Okay, okay, so there’s python3 and python2. But what if I use just python? Well…
$ python
-bash: python: command not found
There is no python command by default.
Why? Frankly, we couldn’t agree what python should do. There are two groups of developers. One expects python to mean Python 2, and the other Python 3. The two don’t always talk to each other, so you might be a member of one camp and not know anyone from the other – but they do exist.
Today, in 2018, the python == python2 side is more popular, even among those that prefer Python 3 (which they spell out as python3). This side is also backed by an official upstream recommendation, PEP 394. However, we expect that this viewpoint will become much less popular over the lifespan of RHEL 8. By making python always mean Python 2, Red Hat would be painting itself into a corner.
Okay, okay, so there’s
python3 and python2. But what if I use just python? Well…$ python
-bash: python: command not found
There is no
python command by default.
Why? Frankly, we couldn’t agree what
python should do. There are two groups of developers. One expects python to mean Python 2, and the other Python 3. The two don’t always talk to each other, so you might be a member of one camp and not know anyone from the other – but they do exist.
Today, in 2018, the
python == python2 side is more popular, even among those that prefer Python 3 (which they spell out as python3). This side is also backed by an official upstream recommendation, PEP 394. However, we expect that this viewpoint will become much less popular over the lifespan of RHEL 8. By making python always mean Python 2, Red Hat would be painting itself into a corner.Unversioned Python command
alternatives --set python /usr/bin/python3
For Python 2, use
/usr/bin/python2 instead. For details on how to revert the changes or do the setup interactively, see man unversioned-python.
Moving on for the live demo:
How to Install Python 3 / Python 2.7 on RHEL 8
The procedure for installing Python 3 on RHEL 8 is as follows:
- Open the Terminal application or window.
- Search for python package in RHEL 8, run: sudo yum search python3
- To install python 3 on RHEL 8, run: sudo yum install python3
- To install python 2 on RHEL 8, run: sudo yum install python2
- Upgrade python 3 in RHEL 8, run: sudo yum upgrade python3
- Upgrade python 2 in RHEL 8, run: sudo yum upgrade python2
Let us see all commands and example in details.
How to find out Python package names on RHEL 8
Try any one of the following syntax along with grep command:
You can show detailed information before installing package as well:
sudo yum search python3 | more
sudo yum search python2 | more
sudo yum search python36
sudo yum search python2 | grep 'python2.x86_64'You can show detailed information before installing package as well:
sudo yum info python2.x86_6
sudo yum info python36RHEL 8 install Python 3
Type the following yum command to install Python 3 on Red Hat Enterprise Linux version 8:
OR
sudo yum install python3OR
sudo yum module install python36
Verify installation by typing the type command/command command:
$ type -a python3
python3 is /usr/bin/python3
$ command -V python3
python3 is hashed (/usr/bin/python3)
$ python3 --version
Python 3.6.6RHEL 8 install Python 2
Let us see how to install Python 2.7 on RHEL 8:
OR
sudo yum install python27OR
sudo yum module install python27
Let us find out information about installed version of Python 2.7 in RHEL 8:
$ type -a python2
$ command -V python2
$ python2 --version
Comments