5

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?

Dominic Cleal
  • 3,205
  • 19
  • 22
user7610
  • 25,267
  • 15
  • 124
  • 150

2 Answers2

8

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.

Robert Kratky
  • 542
  • 3
  • 14
  • 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. – Cognitiaclaeves Jul 14 '17 at 14:26
  • 2
    Unless I'm mistaken, the answer is complete. The package required is 'scl-utils'. – Robert Kratky Jul 14 '17 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. – Cognitiaclaeves Jul 18 '17 at 13:24
  • This KB article is now accessible to the public without an account, from what I see. – Stefan Lasiewski Nov 14 '17 at 20:43
  • This is the link I was referring to as being inaccessible to someone without RedHat account: https://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. – Cognitiaclaeves Nov 29 '17 at 21:50
  • Adding `source scl_source enable python3*` to `~/.bash_profile` worked for me on CentOS 6.9. – ghchoi Apr 21 '20 at 03:50
0

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:

  1. Enable the python through scl script python_enable_3.5 or scl enable rh-python35 bash.

  2. Verify that it's enabled by executing python3.5 --version. This should give you your python version.

  3. 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.)

  4. Awesome, now please exit out of the current shell of scl.

  5. 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
  1. 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"
  1. 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
  1. 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
  1. 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'
  1. For verification, reload the .bashrc by source ~/.bashrc and execute python351 --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.

sam
  • 931
  • 2
  • 13
  • 26
  • Can't you simply put `source scl_source enable python35` into your `.bashrc` and be done? – user7610 Feb 15 '21 at 14:35
  • Tried.My bash got stuck and had to use ftp to reset the `.bashrc` – sam Feb 15 '21 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 ? – Isaac Wassouf May 01 '21 at 23:29
  • @IsaacWassouf Hostgator has the [instruction](https://www.hostgator.com/help/article/what-software-and-program-versions-does-hostgator-offer) for that too (search for `rh-python35` in webpage). Its exactly as how @user7610 said. Add `source 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! – sam May 04 '21 at 16:30
  • 2
    Thanks 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 – Isaac Wassouf May 05 '21 at 23:47