You should try using -- instead of surrounding your command with quotes.

scl enable python27 -- ls /tmp

I was able to make a python script that uses the rh-python35 collection with this shebang:

#!/usr/bin/scl enable rh-python35 -- python

import sys
print(sys.version)
Answer from JM0 on Stack Overflow
🌐
Red Hat
access.redhat.com › discussions › 3279251
Red Hat Customer Portal - Access to 24x7 support and knowledge
January 4, 2018 - When executing scl command remote from other server cause error. Example ssh user1@server1.com scl enable rh-python36 'python /home/user1/setup.py install --user' cause error : Unable to open /etc/scl/conf/python!
Top answer
1 of 3
3

You should try using -- instead of surrounding your command with quotes.

scl enable python27 -- ls /tmp

I was able to make a python script that uses the rh-python35 collection with this shebang:

#!/usr/bin/scl enable rh-python35 -- python

import sys
print(sys.version)
2 of 3
1

The parsing of arguments in the she-bang command is not really defined. From man execve:

The semantics of the optional-arg argument of an interpreter script vary across implementations. On Linux, the entire string following the interpreter name is passed as a single argument to the interpreter, and this string can include white space. However, behavior differs on some other systems. Some systems use the first white space to terminate optional-arg. On some systems, an interpreter script can have multiple arguments, and white spaces in optional-arg are used to delimit the arguments.

No matter what, argument splitting based on quote sis not supported. So when you write:

#!/usr/bin/scl enable python27 "ls /tmp"

It's very possible that what gets invoked is (using bash notation):

'/usr/bin/scl' 'enable' 'python27' '"ls' '/tmp"'

This is probably why it tries to open the "ls file at /etc/scl/prefixes/"ls

But it is just as likely that the shebang evaluates to:

'/usr/bin/scl' 'enable python27 "ls /tmp"'

And that would fail since it wont be able to find a command named enable python27 "ls /tmp" for scl to execute.

There's a few workarounds you can use.

You can call your script via scl:

$ cat myscript
#!/bin/bash
echo hello

$ scl enable python27 ./myscript
hello

You can also use the heredoc notation, but it might lead to subtle issues. I personally avoid this:

$ cat ./myscript
#!/bin/bash
scl enable python27 -- <<EOF
echo hi
echo \$X_SCLS
EOF

$ bash -x myscript 
+ scl enable python27 --
hi
python27

You can see one of the gotcha's already: I had to write \$X_SCLS to access the environment variable instead of just $X_SCL.

Edit: Another option is two have two scripts. One that has the actual code, and the second that simply does scl enable python27 $FIRST_SCRIPT. Then you wont have to remember to enter scl ... manually.

Discussions

linux - Bash skipping python commands - Stack Overflow
So, I installed python 3.3 and scl enable python33 bash makes python3.3 the default in the machine, because my python script.py the one you see in the question can only run with python 3.3 ... Mine is located in /opt/rh/python33/root/usr/bin/python3.3 for some reason, but I wanted to use python ... More on stackoverflow.com
🌐 stackoverflow.com
March 27, 2016
rhel - How do you install Django when there is a problem with scl? - Unix & Linux Stack Exchange
scl is installed on RedHat 6. The man pages for scl work. I want to install Django. I believe that a prerequisite is to install SCL for Python. $scl -l returns nothing. I believe that this is a More on unix.stackexchange.com
🌐 unix.stackexchange.com
June 17, 2016
letsencrypt + Python Problems!
letsencrypt + Python Problems More on forum.centos-webpanel.com
🌐 forum.centos-webpanel.com
install issue on RHEL7
Hi, I have the same issue. i tired both but no luck, any idea · also i'm unable to login from the webpage (not sure if it for the same reason), I'm getting this error More on github.com
🌐 github.com
13
August 31, 2017
🌐
GitHub
gist.github.com › sub-mod › a79ee1c45a2d6ebefe815770f77a5656
glibc ABI issue · GitHub
glibc ABI issue. GitHub Gist: instantly share code, notes, and snippets.
🌐
HostAdvice
hostadvice.com › how to › web hosting › centos › how to install python 3 on centos 7 using scl
How To Install Python 3 On CentOS 7 Using SCL
May 31, 2022 - However, we installed Python 3.6 and that is what we intend to use. Now to access this version, we should make use of the SCL tool to launch a different shell instance: ... The command above will call /opt/rh/rh-python36/enable; a script that changes the variables of a shell environment.
🌐
Oracle
docs.oracle.com › cd › F61410_01 › scl-user › OL-SCL-USER.pdf pdf
Oracle Linux Software Collection Library for Oracle Linux 7 E59096-28
#!/usr/bin/scl enable rh-python36 -- python · import platform · import sys · import os · print(os.system('python -V')) print(platform.python_version()) print(sys.version) For more information, see the scl(1) manual page. Using Services That Are Provided by Software Collections · Some of the software collections install service scripts in /etc/rc.d/init.d that include the ·
Find elsewhere
🌐
Stack Exchange
unix.stackexchange.com › questions › 290500 › how-do-you-install-django-when-there-is-a-problem-with-scl
rhel - How do you install Django when there is a problem with scl? - Unix & Linux Stack Exchange
June 17, 2016 - scl is installed on RedHat 6. The man pages for scl work. I want to install Django. I believe that a prerequisite is to install SCL for Python. $scl -l returns nothing. I believe that this is a
🌐
Jboss
planet.jboss.org › post › maintain_software_collections_easily_on_thousands_of_machines_using_scl_register
Blogs - JBoss.org
June 29, 2015 - BRZ migrated the Austrian Business Service Portal with 2M+ users to Keycloak. The Austrian Business Service Portal (USP) is the central online eGovernment platform for entrepreneurs and businesses. It connects businesses with various Austrian online… · These are some of the blogs I follow ...
🌐
Red Hat
docs.redhat.com › en › documentation › red_hat_software_collections › 3 › html › 3.8_release_notes › chap-rhscl
Chapter 1. Red Hat Software Collections 3.8 | 3.8 Release Notes | Red Hat Software Collections | 3 | Red Hat Documentation
Some utilities, for example, su, login, or screen, do not export environment settings in all cases, which can lead to unexpected results. It is therefore recommended to use sudo instead of su and set the env_keep environment variable in the /etc/sudoers file. Alternatively, you can run commands in a reverse order; for example: su -l postgres -c "scl enable rh-postgresql94 psql"
🌐
GitHub
github.com › MISP › MISP › issues › 2430
install issue on RHEL7 · Issue #2430 · MISP/MISP
August 31, 2017 - /var/tmp/sclaPcqKl: line 8: /var/www/MISP/app/Console/worker/start.sh: Permission denied ! [root@XXXX ~]# su -s /bin/bash apache -c 'scl enable rh-php56 bash -c /var/www/MISP/app/Console/worker/start.sh' Unable to open /etc/scl/conf/bash!
Author   MISP
🌐
Red Hat
docs.redhat.com › en › documentation › red_hat_software_collections › 3 › html › 3.3_release_notes › chap-rhscl
Chapter 1. Red Hat Software Collections 3.3 | 3.3 Release Notes | Red Hat Software Collections | 3 | Red Hat Documentation
Some utilities, for example, su, login, or screen, do not export environment settings in all cases, which can lead to unexpected results. It is therefore recommended to use sudo instead of su and set the env_keep environment variable in the /etc/sudoers file. Alternatively, you can run commands in a reverse order; for example: su -l postgres -c "scl enable rh-postgresql94 psql"
🌐
Reddit
reddit.com › r/redhat › how to add packages to scl
r/redhat on Reddit: How to add packages to SCL
April 22, 2022 -

First time working with SCL so please forgive me. Maybe I'm missing something obvious, I just don't know. I recently deployed an instance of RH8 on AWS. I installed a couple version of Python - Python 3.7 and 3.9.

However when I use the following command I get no results.

root@ip-testmachine : scl list-collections

I thought that by installing the software package yum install <package> it automatically gets added to the SCL manager. Do I have do something else to have them added so I can enable them?

Any help would be appreciated.

🌐
Red Hat
docs.redhat.com › documentation › en-us › red_hat_software_collections › 3 › html-single › 3.5_release_notes
3.5 Release Notes | Red Hat Software Collections | 3 | Red Hat Documentation
Some utilities, for example, su, login, or screen, do not export environment settings in all cases, which can lead to unexpected results. It is therefore recommended to use sudo instead of su and set the env_keep environment variable in the /etc/sudoers file. Alternatively, you can run commands in a reverse order; for example: su -l postgres -c "scl enable rh-postgresql94 psql"
🌐
Red Hat
access.redhat.com › solutions › 527703
How can I make a Red Hat Software Collection persist after a reboot/logout? - Red Hat Customer Portal
However, software collections will be properly enabled only for daemon processes, not for processes that interact with these daemons and are run by users (like mysql CLI, mysqldump utility, etc.). The usual way to enable software collections for whole sessions is to run a new bash wrapped with "scl enable" call, for example like that:
🌐
Red Hat
docs.redhat.com › en › documentation › red_hat_software_collections › 3 › html › 3.7_release_notes › chap-rhscl
Chapter 1. Red Hat Software Collections 3.7 | 3.7 Release Notes | Red Hat Software Collections | 3 | Red Hat Documentation
Some utilities, for example, su, login, or screen, do not export environment settings in all cases, which can lead to unexpected results. It is therefore recommended to use sudo instead of su and set the env_keep environment variable in the /etc/sudoers file. Alternatively, you can run commands in a reverse order; for example: su -l postgres -c "scl enable rh-postgresql94 psql"
🌐
Red Hat
docs.redhat.com › en › documentation › red_hat_software_collections › 3 › html › 3.2_release_notes › chap-rhscl
Chapter 1. Red Hat Software Collections 3.2 | 3.2 Release Notes | Red Hat Software Collections | 3 | Red Hat Documentation
Some utilities, for example, su, login, or screen, do not export environment settings in all cases, which can lead to unexpected results. It is therefore recommended to use sudo instead of su and set the env_keep environment variable in the /etc/sudoers file. Alternatively, you can run commands in a reverse order; for example: su -l postgres -c "scl enable rh-postgresql94 psql"