How to install Python 3 on RHEL

  1. Become root.
  2. Enable the rhscl and optional software repos using subscription-manager.
  3. Use yum to install @development. This makes sure you’ve got GCC, makegit, etc. so you can build any modules that contain compiled code.
  4. Use yum to install rh-python36.
  5. Optional: Use yum to install python-toolsnumpyscipy, and six from RHSCL RPMs.
1
2
3
4
5
6
7
8
9
10
11
12
$ su -
# subscription-manager repos --enable rhel-7-server-optional-rpms \
  --enable rhel-server-rhscl-7-rpms
# yum -y install @development
# yum -y install rh-python36
# yum -y install rh-python36-numpy \
 rh-python36-scipy \
 rh-python36-python-tools \
 rh-python36-python-six
# exit

Using Python 3 on RHEL

  1. Under your normal user ID, run scl enable to add python 3 to your path(s).
  2. Create a Python virtual environment and activate it. (Note: your prompt has changed to show the virtual environment.)
  3. Install whatever additional modules you need with pip in an isolated environment without being root.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
$ scl enable rh-python36 bash
$ python3 -V
Python 3.6.3
$ python -V  # python now also points to Python3
Python 3.6.3
$ mkdir ~/pydev
$ cd ~/pydev
$ python3 -m venv py36-venv
$ source py36-venv/bin/activate
(py36-venv) $ python3 -m pip install ...some modules...

If you start a new session, here are the steps for using your virtual environment:

1
2
3
4
$ scl enable rh-python36 bash
$ cd ~/pydev
$ source py36-env/bin/activate

Why use Red Hat Software Collections

The benefit of using Red Hat Software Collections is that you can have multiple versions of Python installed at the same time along with the base Python 2.7 that shipped with RHEL 7. You can easily switch between versions with scl enable.

Note: The latest stable packages for .Net Core, Go, Rust, PHP 7, Ruby 2.5, GCC, Clang/LLVM, Nginx, MongoDB, MariaDB, PostgreSQL, and more are all yum– installable as software collections. So you should take the time to get comfortable with software collections.

Using software collections requires an extra step because you have to enable the collection you want to use. Enabling just adds the necessary paths (PATHMANPATHLD_LIBRARY_PATH) to your environment. Once you get the hang of it, software collections are fairly easy to use. It really helps to understand the way that environment-variable changes work in Linux/UNIX. Changes can be made only to the current process. When a child process is created, it inherits the environment of the parent. Any environment changes made in the parent after the child has been created will have no effect on the child. Therefore, the changes made by scl enable will affect only the current terminal session or anything started from it. This article also shows how you can permanently enable a software collection for your user account.

2 KOMENTARZE

ZOSTAW ODPOWIEDŹ

Please enter your comment!
Please enter your name here