Permanently enable RHEL scl

14,340

Solution 1

Well, you could add something to your startup script to source the enable script.

Eg add to your .bash_profile (note space between initial dot and /)

. /opt/rh/python27/enable

Solution 2

This option sounds dangerous to me for root. I would think something like the following would be safer and more appropriate:

You can create a function that takes command line options. Think of this as an alias on steroids. Add the following to your .bashrc

python27() {
scl enable python27 “python $*”
}

Then test:

python27 –version
Python 2.7.5

This doesn’t help with your magic line in scripts, but will make it easier to call scripts:

[smccarty@keith ~]$ cat script.py
#!/usr/bin/env python27

import sys

print “Hello, World!”, sys.version

Call it normal and notice, the default installation of python is used:

[smccarty@keith ~]$ ./script.py
Hello, World! 2.6.6 (r266:84292, Sep 4 2013, 07:46:00)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-3)]

Call it with our alias, and notice that Python 2.7 is used:

[smccarty@keith ~]$ python27 script.py
Hello, World! 2.7.5 (default, May 23 2013, 06:08:09)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-3)]
Share:
14,340

Related videos on Youtube

paweloque
Author by

paweloque

My current projects: https://orbit7.ch https://gobugfree.com Follow me on Twitter: @paweloque

Updated on June 26, 2022

Comments

  • paweloque
    paweloque almost 2 years

    Is there a way to permanently enable custom Software Collections for RedHat?

    I have installed an scl to provide python27 in RHEL6 and don't want to have to enable the custom scl every time.

  • mogul
    mogul almost 10 years
    It seems to break if script.py is renamed to a name containing a space, like "abc def.py"
  • Tomas Tomecek
    Tomas Tomecek over 9 years
    Putting it to /etc/profile.d/ is much better solution. What if the person is not a bash user?