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 OverflowYou 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)
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.
linux - Bash skipping python commands - Stack Overflow
rhel - How do you install Django when there is a problem with scl? - Unix & Linux Stack Exchange
letsencrypt + Python Problems!
install issue on RHEL7
using scl enable actually opens a new shell inside your current one, which is quite unclean, especially if done from a login script.
You should place, instead, in your ~/.bash_profile:
source /opt/rh/rh-nginx18/enable
or:
source scl_source enable rh-nginx18
The latter is more "elegant" as it is independent from the actual installation path.
This has the effect of loading the environment in your current shell.
Redhat proposes placing a file in /etc/profile.d, i.e. for python:
$ cat /etc/profile.d/enablepython33.sh
#!/bin/bash
source scl_source enable python33
As this works for the devtools under centos for me you could try this.
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.
SHELL is completely the wrong Dockerfile command for this. You'll probably want to put that in a RUN stanza instead.
The purpose of SHELL is to define the shell used to execute RUN commands. So something like
SHELL ["sh", "-c"] # The default
RUN echo "foo"
ends up running
sh -c 'echo "foo"'
Of course, replacing SHELL with a command which doesn't support this use case will simply break the RUN command for you.
Maybe try something like
FROM centos:7
RUN mkdir -p /usr/src/app && \
yum install -y centos-release-scl && \
yum install -y rh-python36 && \
yum install -y rh-python36-python-tkinter
WORKDIR /usr/src/app
COPY . .
WORKDIR /usr/src/app/codeBase
RUN scl enable rh-python36 pip install --no-cache-dir -r ./requirements.txt
EXPOSE 9000
CMD ["scl", "enable", "rh-python36", "python", "run.py"]
So I figured this out thanks to the answer from C.Nivs and an answer here. The alias works in an interactive shell, but not for the CMD. What I ended up doing was similar, only in my case I'm creating a new executable in /usr/bin that calls the special python36 exe:
RUN echo -e '#!/bin/bash\n$(find / -type f -name "python*" | grep "python3.6$") "$@"' > /usr/bin/py3 && \
chmod +x /usr/bin/py3
CMD ["py3", "-V"]
now py3 runs a script calling the python3 install specifically with whatever argument