I followed the Software Collections Quick Start and I now have Python 3.5 installed. How can I make it always enabled in my ~/.bashrc
, so that I do not have to enable it manually with scl enable rh-python35 bash
?
2 Answers
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.
-
I believe that this is the best answer. Unfortunately, that page hides the solution and is inaccessible to someone without a RedHat account. The above appears to only be part of the answer. Additionally, some special package appears to be needed for the solution above to work. Commented Jul 14, 2017 at 14:26
-
2Unless I'm mistaken, the answer is complete. The package required is 'scl-utils'. Commented Jul 14, 2017 at 17:55
-
I ran into an issue when trying to use it in a container, which led me to believe that the answer was incomplete. I'll check and see if I'm using scl-utils in the dockerfile. Commented Jul 18, 2017 at 13:24
-
This KB article is now accessible to the public without an account, from what I see. Commented Nov 14, 2017 at 20:43
-
This is the link I was referring to as being inaccessible to someone without RedHat account: bugzilla.redhat.com/show_bug.cgi?id=874417 It appears to still be unavailable to someone without a redhat account. ... With that said, though, I don't need to access that link to understand the solution. I guess I was just having trouble reading that day. Commented Nov 29, 2017 at 21:50
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.5
orscl enable rh-python35 bash
.Verify that it's enabled by executing
python3.5 --version
. This should give you your python version.Execute
which python3.5
to 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
exit
out 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
so
file.locate
doesn'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
.bashrc
bysource ~/.bashrc
and 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.
-
Can't you simply put
source scl_source enable python35
into your.bashrc
and be done?– user7610Commented Feb 15, 2021 at 14:35 -
Tried.My bash got stuck and had to use ftp to reset the
.bashrc
– samCommented Feb 15, 2021 at 14:53 -
Wait So I can install python3 on Hostgator shared hosting? I though you can only install python2 ! Would you care to explain how did you install it ?– IsaacCommented May 1, 2021 at 23:29
-
@IsaacWassouf Hostgator has the instruction for that too (search for
rh-python35
in webpage). Its exactly as how @user7610 said. Addsource scl_source enable rh-python35
in.bashrc
file. It didn't work for me first few times, so I had to follow all above steps in the answer. I hope single line works for you on your first time. Cheers!– samCommented May 4, 2021 at 16:30 -
2Thanks for the answer! It worked by just adding
source scl_source enable rh-python35
in.bashrc
as you mentioned! By any chance do you have any idea of how to deploy a Django app in shared hosting? All the tutorials I've seen require using the "Setup Python app" under the Software section which is not supported in shared hosting as I understood from customer service– IsaacCommented May 5, 2021 at 23:47