Python 2.7 install on Scientific Linux 6 via SCL devtoolset

5,837

You should verify that python27 is coming from SCL and not elsewhere.

In my case I am using CentOS 6, but the process is the same.

So:

$ yum info python27  
Loaded plugins: fastestmirror, priorities
Loading mirror speeds from cached hostfile
6 packages excluded due to repository priority protections
Available Packages
Name        : python27
Arch        : x86_64
Version     : 1.1
Release     : 25.el6
Size        : 5.2 k
Repo        : centos-sclo-rh
Summary     : Package that installs python27
License     : GPLv2+
Description : This is the main package for python27 Software Collection.

We can see it comes from centos-sclo-rh and so is the right version.

We can install this. Because it's from SCL it will install into /opt/rh and this will not impact any other aspect of the OS:

$ sudo yum install python27
...
$ ls /opt/rh
python27

We can see the default python is still unchanged:

$ /usr/bin/python --version
Python 2.6.6

Now we need the scl command. This is from the scl-utils package, which you may need to install (yum install scl-utils).

$ scl enable python27 bash

This runs a new shell with the path changed:

$ scl enable python27 bash
bash-4.1$ echo $PATH
/opt/rh/python27/root/usr/bin:/usr/local/bin:/usr/bin/X11:/etc:/usr/local/sbin:/sbin:/usr/sbin
bash-4.1$ command -v python
/opt/rh/python27/root/usr/bin/python
bash-4.1$ python --version
Python 2.7.8

So enabling and running SCL does not impact the core OS; it won't break anything you normally run but allows for a newer version of python to be installed in parallel (in /opt/rh).

Share:
5,837

Related videos on Youtube

slkuser
Author by

slkuser

Updated on September 18, 2022

Comments

  • slkuser
    slkuser almost 2 years

    I understand Scientific Linux 6 uses Python 2.6.6 for several critical utils, including yum, according to this article How to install Python 27 on Centos 6

    The simplest and hopefully cleanest install I found is based on Red Hat Software Collection and the devtoolset-3 package which I already installed according to Compiling in Scientific Linux

    I stopped at the next step:

    yum install python27
    scl enable python27 bash
    

    Could you advise whether it will be 'safe' to proceed further as instructed without an alt-install. Thanks.

    • grochmal
      grochmal almost 8 years
      The gihub you link is about the installation of python-sopnet not python itself. Are you trying to install python-sopnet or just python 2.7.12?
    • slkuser
      slkuser almost 8 years
      python 2.7.12. Thanks for raising this point.
  • grochmal
    grochmal almost 8 years
    /opt/rh/python27/root/usr/bin/python is a soft link, which ends at /opt/rh/python27/root/usr/bin/python2.7. An alternative too using scl to call a new shell is to add a soft link (e.g. /usr/local/bin/python2.7) and explicitly state the use of python2.7 in the scripts that need it. Hacky, yes, but still explicit enough to not confuse people that will do which python2.7. Good answer btw (+1)
  • slkuser
    slkuser almost 8 years
    @Stephen: thanks so much for posting such a detailed answer. I have slc6-scl for repo as expected since I fetched SCL/devtoolset-3 from [SL] (root.cern.ch/phpBB3/viewtopic.php?t=18262). Any idea where it will install to in /opt?
  • Stephen Harris
    Stephen Harris almost 8 years
    If the SCL stuff is built to be compatible with RH, it should be in /opt/rh the same as the CentOS version.
  • slkuser
    slkuser almost 8 years
    Reporting back: successful install of python 2.7 in /opt/rh where devtoolset-3 took residence. In short, it works for Scientific Linux 6 too. Thanks so much again.