Oracle Linux 7 doesn’t come with Python 3 by default but only with Python 2. Luckily, installing Python 3 can be done with two simple steps:
sudo yum install -y oracle-epel-release-el7
sudo yum install -y python36
The first step installs and enables the Oracle EPEL yum repository (EPEL – Extra Packages for Enterprise Linux) which includes the Python 3.6 version. In case the repository is already installed, yum
will detect that and do nothing. So nothing will go wrong if you execute the command unnecessarily or twice.
[gerald@localhost ~]$ sudo yum install -y oracle-epel-release-el7 Loaded plugins: ulninfo ol7_UEKR5 | 2.5 kB 00:00:00 ol7_latest | 2.7 kB 00:00:00 (1/5): ol7_UEKR5/x86_64/updateinfo | 33 kB 00:00:00 (2/5): ol7_latest/x86_64/group | 810 kB 00:00:00 (3/5): ol7_latest/x86_64/updateinfo | 918 kB 00:00:00 (4/5): ol7_UEKR5/x86_64/primary_db | 3.9 MB 00:00:01 (5/5): ol7_latest/x86_64/primary_db | 16 MB 00:00:02 Resolving Dependencies --> Running transaction check ---> Package oracle-epel-release-el7.x86_64 0:1.0-2.el7 will be installed --> Finished Dependency Resolution Dependencies Resolved ======================================================================================================================================= Package Arch Version Repository Size ======================================================================================================================================= Installing: oracle-epel-release-el7 x86_64 1.0-2.el7 ol7_latest 14 k Transaction Summary ======================================================================================================================================= Install 1 Package Total download size: 14 k Installed size: 18 k Downloading packages: oracle-epel-release-el7-1.0-2.el7.x86_64.rpm | 14 kB 00:00:00 Running transaction check Running transaction test Transaction test succeeded Running transaction Installing : oracle-epel-release-el7-1.0-2.el7.x86_64 1/1 Verifying : oracle-epel-release-el7-1.0-2.el7.x86_64 1/1 Installed: oracle-epel-release-el7.x86_64 0:1.0-2.el7 Complete! [gerald@localhost ~]$
Now you are ready to install Python 3, version 3.6 in this case:
[gerald@localhost ~]$ sudo yum install -y python36 Loaded plugins: ulninfo Resolving Dependencies --> Running transaction check ---> Package python36.x86_64 0:3.6.8-1.el7 will be installed --> Processing Dependency: python36-libs(x86-64) = 3.6.8-1.el7 for package: python36-3.6.8-1.el7.x86_64 --> Processing Dependency: libpython3.6m.so.1.0()(64bit) for package: python36-3.6.8-1.el7.x86_64 --> Running transaction check ---> Package python36-libs.x86_64 0:3.6.8-1.el7 will be installed --> Finished Dependency Resolution Dependencies Resolved ======================================================================================================================================= Package Arch Version Repository Size ======================================================================================================================================= Installing: python36 x86_64 3.6.8-1.el7 ol7_developer_EPEL 66 k Installing for dependencies: python36-libs x86_64 3.6.8-1.el7 ol7_developer_EPEL 8.6 M Transaction Summary ======================================================================================================================================= Install 1 Package (+1 Dependent package) Total download size: 8.6 M Installed size: 36 M Downloading packages: (1/2): python36-3.6.8-1.el7.x86_64.rpm | 66 kB 00:00:00 (2/2): python36-libs-3.6.8-1.el7.x86_64.rpm | 8.6 MB 00:00:01 --------------------------------------------------------------------------------------------------------------------------------------- Total 7.3 MB/s | 8.6 MB 00:00:01 Running transaction check Running transaction test Transaction test succeeded Running transaction Installing : python36-libs-3.6.8-1.el7.x86_64 1/2 Installing : python36-3.6.8-1.el7.x86_64 2/2 Verifying : python36-3.6.8-1.el7.x86_64 1/2 Verifying : python36-libs-3.6.8-1.el7.x86_64 2/2 Installed: python36.x86_64 0:3.6.8-1.el7 Dependency Installed: python36-libs.x86_64 0:3.6.8-1.el7 Complete! [gerald@localhost ~]$
You can verify the installation via python36 --version
:
[gerald@localhost ~]$ python36 --version Python 3.6.8 [gerald@localhost ~]$
Hi,
On my machine, i get this error. How to resolve this.
yum install -y oracle-epel-release-el7
Loaded plugins: fastestmirror, langpacks, ulninfo, versionlock
Loading mirror speeds from cached hostfile
epel/x86_64/metalink | 18 kB 00:00:00
Could not retrieve mirrorlist http://pd-yum-slc-01.us.oracle.com/pditrepos/mirrorlists/ol7_developer_uekr5 error was
14: HTTP Error 502 – Bad Gateway
One of the configured repositories failed (Unknown),
and yum doesn’t have enough cached data to continue. At this point the only
safe thing yum can do is fail. There are a few ways to work “fix” this:
Cannot find a valid baseurl for repo: ol7_developer_uekr5
LikeLike
Hi Saravanan,
It looks like that yum is not able to connect to the yum repository on the web:
HTTP Error 502 – Bad Gateway
This is most likely a temporary problem as has itself corrected by now.
Thx,
LikeLike
hi Gerald,
Nice post. Will this work for python 3.8.3 for example?
LikeLike
Thanks Parag,
Yeah should be the same, just type python38.
Thx,
LikeLike
hi Gerald,
It actually does not work ‘No package python38 available’
now i tried with 3.6.8 but when i do pip3 it gives
Traceback (most recent call last):
File “/bin/pip3”, line 8, in
from pip import main
File “/usr/lib/python3.6/site-packages/pip/init.py”, line 42, in
from pip.utils import get_installed_distributions, get_prog
File “/usr/lib/python3.6/site-packages/pip/utils/init.py”, line 27, in
from pip._vendor import pkg_resources
File “/usr/lib/python3.6/site-packages/pip/_vendor/pkg_resources/init.py”, line 35, in
import plistlib
File “/usr/lib64/python3.6/plistlib.py”, line 65, in
from xml.parsers.expat import ParserCreate
File “/usr/lib64/python3.6/xml/parsers/expat.py”, line 4, in
from pyexpat import *
ImportError: /usr/lib64/python3.6/lib-dynload/pyexpat.cpython-36m-x86_64-linux-gnu.so: undefined symbol: XML_SetHashSalt
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File “/bin/pip3”, line 12, in
from pip._internal import main
File “/usr/lib/python3.6/site-packages/pip/init.py”, line 42, in
from pip.utils import get_installed_distributions, get_prog
File “/usr/lib/python3.6/site-packages/pip/utils/init.py”, line 27, in
from pip._vendor import pkg_resources
File “/usr/lib/python3.6/site-packages/pip/_vendor/pkg_resources/init.py”, line 35, in
import plistlib
File “/usr/lib64/python3.6/plistlib.py”, line 65, in
from xml.parsers.expat import ParserCreate
File “/usr/lib64/python3.6/xml/parsers/expat.py”, line 4, in
from pyexpat import *
LikeLike
Hi Parag,
Indeed, it appears that Python 3.8 is only shipped with Oracle Linux 8 as part of the AppStream Latest repository: https://yum.oracle.com/repo/OracleLinux/OL8/appstream/x86_64/index.html
I see you already found the solution to your other issue on Stackoverflow. 🙂
Thx,
LikeLike