How to install Python 3 on Oracle Linux

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:

  1. sudo yum install -y oracle-epel-release-el7
  2. 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 ~]$

6 thoughts on “How to install Python 3 on Oracle Linux

  1. 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:

     1. Contact the upstream for the repository and get them to fix the problem.
    
     2. Reconfigure the baseurl/etc. for the repository, to point to a working
        upstream. This is most often useful if you are using a newer
        distribution release than is supported by the repository (and the
        packages for the previous distribution release still work).
    
     3. Run the command with the repository temporarily disabled
            yum --disablerepo=<repoid> ...
    
     4. Disable the repository permanently, so yum won't use it by default. Yum
        will then just ignore the repository until you permanently enable it
        again or use --enablerepo for temporary usage:
    
            yum-config-manager --disable <repoid>
        or
            subscription-manager repos --disable=<repoid>
    
     5. Configure the failing repository to be skipped, if it is unavailable.
        Note that yum will try to contact the repo. when it runs most commands,
        so will have to try and fail each time (and thus. yum will be be much
        slower). If it is a very temporary problem though, this is often a nice
        compromise:
    
            yum-config-manager --save --setopt=<repoid>.skip_if_unavailable=true
    

    Cannot find a valid baseurl for repo: ol7_developer_uekr5

    Like

    1. 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,

      Like

      1. 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 *

        Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.