4

I have rebuilt the VM; it is an out of the box install. I just need 3.6.1 installed and available for all users without 2.7.5 interfering with it. If it's easier / possible to uninstall 2.7.5, then I'm cool with that.

2
  • tecadmin.net/install-python-3-6-on-centos might help
    – Munir
    Jul 10, 2017 at 21:59
  • Linux version 3.10.0-514.el7.x86_64 (mockbuild@x86-039.build.eng.bos.redhat.com) (gcc version 4.8.5 20150623 (Red Hat 4.8.5-11) (GCC) ) #1 SMP Wed Oct 19 11:24: 13 EDT 2016
    – nuprap
    Jul 10, 2017 at 23:14

5 Answers 5

2

If 3.5 is good enough, then use the Red Hat's Software Collection (RHSCL) version of Python, rh-python35. Installs happily alongside the older version of Python. https://access.redhat.com/documentation/en-US/Red_Hat_Software_Collections/2/html/2.4_Release_Notes/chap-RHSCL.html#sect-RHSCL-Features

1

Every time that i need to use multiple python versions on any system i use Pyenv, you can use it on a per user role or just use it globally.

Pyenv Website

From their readme:

pyenv lets you easily switch between multiple versions of Python. It's simple, unobtrusive, and follows the UNIX tradition of single-purpose tools that do one thing well.

0

You cannot replace the system version of Python with a different version. A significant amount of startup scripts and system services depend on the version of Python shipped with the OS remaining constant. You will need to download a relocatable binary RPM or a source package and install it manually. In some versions of RHEL with Python 2.x shipped, there are python3 packages available that will install Python 3.x in an alternate location for you, to find them you can do yum list | grep python3. Without knowing what version of RHEL you are concerned with, I cannot be more specific.

1
  • Linux version 3.10.0-514.el7.x86_64 (mockbuild@x86-039.build.eng.bos.redhat.com) (gcc version 4.8.5 20150623 (Red Hat 4.8.5-11) (GCC) ) #1 SMP Wed Oct 19 11:24: 13 EDT 2016
    – nuprap
    Jul 10, 2017 at 23:14
0

Python 2.7 is needed for the proper operation of RedHat Linux, things like yum depend on it. So do not uninstall it, and keep it as the primary python for the root user. Python 3 can be installed in parallel, however you will need to compile it from source. Install it in a place like /opt/python3, and modify the PATH and PYTHONPATH environment variables for your users for instance in /etc/profile.d

0

(This is for Python 3.5, but it is almost the same for 3.6)

Installing from RPM is generally better, because:

  • you can install and uninstall (properly) python3.
  • the installation time is way faster. If you work in a cloud environment with multiple VMs, compiling python3 on each VMs is not acceptable.

Solution 1: Red Hat & EPEL repositories

Red Hat has added Python 3.4 for CentOS 6 and 7 through the EPEL repository.

Unfortunately:

  • pip3 is not bundled in any RPM. You need to install it manually (see below).
  • pyvenv is bugged and doesn't work. You need to use virtualenv.

[EPEL] How to install Python 3.4 on CentOS 6 & 7

sudo yum install -y epel-release
sudo yum install -y python34

# Install pip3
sudo yum install -y python34-setuptools  # install easy_install-3.4
sudo easy_install-3.4 pip

# I guess you would like to install virtualenv or virtualenvwrapper
sudo pip3 install virtualenv
sudo pip3 install virtualenvwrapper

If you want to use pyvenv, you can do the following to install pip3 in your virtualenv:

pyvenv --without-pip my_env
curl https://bootstrap.pypa.io/get-pip.py | my_env/bin/python

But if you want to have it out-of-the-box, you can add this bash function (alias) in your .bashrc:

pyvenv() { /usr/bin/pyvenv --without-pip $@; for env in $@; do curl https://bootstrap.pypa.io/get-pip.py | "$env/bin/python"; done; }

Solution 2: IUS Community repositories

The IUS Community provides some up-to-date packages for RHEL & CentOS. The guys behind are from Rackspace, so I think that they are quite trustworthy...

https://ius.io/

Check the right repo for you here:

https://ius.io/GettingStarted/

[IUS] How to install Python 3.5 on CentOS 6

sudo yum install -y https://centos6.iuscommunity.org/ius-release.rpm
sudo yum install -y python35u python35u-pip

# I guess you would like to install virtualenv or virtualenvwrapper
sudo pip3.5 install virtualenv
sudo pip3.5 install virtualenvwrapper

Note: you have pyvenv-3.5 available out-of-the-box if you don't want to use virtualenv.

[IUS] How to install Python 3.5 on CentOS 7

sudo yum install -y https://centos7.iuscommunity.org/ius-release.rpm
sudo yum install -y python35u python35u-pip

# I guess you would like to install virtualenv or virtualenvwrapper
sudo pip3.5 install virtualenv
sudo pip3.5 install virtualenvwrapper

Note: you have pyvenv-3.5 available out-of-the-box if you don't want to use virtualenv.

Source: https://stackoverflow.com/a/23317640/1908115

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.