Use the scl_source feature.
Create a new file in /etc/profile.d/ to enable your collection automatically on start up:
$ cat /etc/profile.d/enablepython35.sh
#!/bin/bash
source scl_source enable python35
See How can I make a Red Hat Software Collection persist after a reboot/logout? for background and details.
Answer from Robert Kratky on Stack OverflowUse the scl_source feature.
Create a new file in /etc/profile.d/ to enable your collection automatically on start up:
$ cat /etc/profile.d/enablepython35.sh
#!/bin/bash
source scl_source enable python35
See How can I make a Red Hat Software Collection persist after a reboot/logout? for background and details.
This answer would be helpful to those who have limited auth access on the server.
I had a similar problem for python3.5 in HostGator's shared hosting. Python3.5 had to be enabled every single damn time after login. Here are my 10 steps for the resolution:
Enable the python through scl script
python_enable_3.5orscl enable rh-python35 bash.Verify that it's enabled by executing
python3.5 --version. This should give you your python version.Execute
which python3.5to get its path. In my case, it was/opt/rh/rh-python35/root/usr/bin/python3.5. You can use this path to get the version again (just to verify that this path is working for you.)Awesome, now please
exitout of the current shell ofscl.Now, lets get the version again through this complete python3.5 path
/opt/rh/rh-python35/root/usr/bin/python3.5 --version.It won't give you the version but an error. In my case, it was
/opt/rh/rh-python35/root/usr/bin/python3.5: error while loading shared libraries: libpython3.5m.so.rh-python35-1.0: cannot open shared object file: No such file or directory
As mentioned in Tamas' answer, we gotta find that
sofile.locatedoesn't work in shared hosting and you can't install that too.Use the following command to find where that file is located:
find /opt/rh/rh-python35 -name "libpython3.5m.so.rh-python35-1.0"
- Above command would print the complete path (second line) of the file once located. In my case, output was
find: `/opt/rh/rh-python35/root/root': Permission denied
/opt/rh/rh-python35/root/usr/lib64/libpython3.5m.so.rh-python35-1.0
- Here is the complete command for the python3.5 to work in such shared hosting which would give the version,
LD_LIBRARY_PATH=/opt/rh/rh-python35/root/usr/lib64 /opt/rh/rh-python35/root/usr/bin/python3.5 --version
- Finally, for shorthand, append the following alias in your ~/.bashrc
alias python351='LD_LIBRARY_PATH=/opt/rh/rh-python35/root/usr/lib64 /opt/rh/rh-python35/root/usr/bin/python3.5'
- For verification, reload the
.bashrcbysource ~/.bashrcand executepython351 --version.
Well, there you go, now whenever you login again, you have got python351 to welcome you.
This is not just limited to python3.5, but can be helpful in case of other scl installed softwares.
How to add packages to SCL
python - How to use scl enable to run python3 app in dockerfile - Stack Overflow
python - How can I make Python3.6, Red Hat Software Collection, persist after a reboot/logout/login? - Stack Overflow
How to use scl enable python command call with in bash shell script?
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