I'm trying to install python3 on RHEL using the following steps:
yum search python3
Which returned No matches found for: python3
Followed by:
yum search python
None of the search results contained python3. What should I try next?
I'm trying to install python3 on RHEL using the following steps:
yum search python3
Which returned No matches found for: python3
Followed by:
yum search python
None of the search results contained python3. What should I try next?
It is easy to install it manually:
Download (there may be newer releases on Python.org):
$ wget https://www.python.org/ftp/python/3.4.3/Python-3.4.3.tar.xz
Unzip
$ tar xf Python-3.*
$ cd Python-3.*
Prepare compilation
$ ./configure
Build
$ make
Install
$ make install
OR if you don't want to overwrite the python
executable (safer, at least on some distros yum
needs python
to be 2.x, such as for RHEL6) - you can install python3.*
as a concurrent instance to the system default with an altinstall
:
$ make altinstall
Now if you want an alternative installation directory, you can pass --prefix
to the configure
command.
Example: for 'installing' Python in /opt/local, just add --prefix=/opt/local
.
After the make install
step: In order to use your new Python installation, it could be, that you still have to add the [prefix]/bin to the $PATH
and [prefix]/lib to the $LD_LIBRARY_PATH
(depending of the --prefix
you passed)
Installing from RPM is generally better, because:
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
.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; }
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/
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
.
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
.
In addition to gecco's answer I would change step 3 from:
./configure
to:
./configure --prefix=/opt/python3
Then after installation you could also:
# ln -s /opt/python3/bin/python3 /usr/bin/python3
It is to ensure that installation will not conflict with python installed with yum.
See explanation I have found on Internet:
http://www.hosting.com/support/linux/installing-python-3-on-centosredhat-5x-from-source
Use the SCL repos.
sudo sh -c 'wget -qO- http://people.redhat.com/bkabrda/scl_python33.repo >> /etc/yum.repos.d/scl.repo'
sudo yum install python33
scl enable python27
(This last command will have to be run each time you want to use python27 rather than the system default.)
You can download a source RPMs and binary RPMs for RHEL6 / CentOS6 from here
This is a backport from the newest Fedora development source rpm to RHEL6 / CentOS6
Along with Python 2.7 and 3.3, Red Hat Software Collections now includes Python 3.4 - all work on both RHEL 6 and 7.
RHSCL 2.0 docs are at https://access.redhat.com/documentation/en-US/Red_Hat_Software_Collections/
Plus lot of articles at developerblog.redhat.com.
edit
# 1. Install the Software Collections tools:
yum install scl-utils
# 2. Download a package with repository for your system.
# (See the Yum Repositories on external link. For RHEL/CentOS 6:)
wget https://www.softwarecollections.org/en/scls/rhscl/rh-python34/epel-6-x86_64/download/rhscl-rh-python34-epel-6-x86_64.noarch.rpm
# or for RHEL/CentOS 7
wget https://www.softwarecollections.org/en/scls/rhscl/rh-python34/epel-7-x86_64/download/rhscl-rh-python34-epel-7-x86_64.noarch.rpm
# 3. Install the repo package (on RHEL you will need to enable optional channel first):
yum install rhscl-rh-python34-*.noarch.rpm
# 4. Install the collection:
yum install rh-python34
# 5. Start using software collections:
scl enable rh-python34 bash
Python3 was recently added to EPEL7 as Python34.
There is ongoing (currently) effort to make packaging guidelines about how to package things for Python3 in EPEL7.
See https://bugzilla.redhat.com/show_bug.cgi?id=1219411
and https://lists.fedoraproject.org/pipermail/python-devel/2015-July/000721.html
I was having the same issue using the python 2.7. Follow the below steps to upgrade successfully to 3.6. You can also try this one-
See before upgrading version is 2.x
python --version
Python 2.7.5
Use below command to upgrade your python to 3.x version-
yum install python3x
replace x with the version number you want.
i.e. for installing python 3.6 execute
yum install python36
After that if you want to set this python for your default version then in bashrc file add
vi ~/.bashrc
alias python='python3.6'
execute bash command to apply the settings
bash
Now you can see the version below
python --version
Python 3.6.3
If you want official RHEL packages you can use RHSCL (Red Hat Software Collections)
More details:
You have to have access to Red Hat Customer Portal to read full articles.
Here are the steps i followed to install Python3:
yum install wget
wget https://www.python.org/ftp/python/3.6.0/Python-3.6.0.tar.xz
sudo tar xvf Python-3.*
cd Python-3.*
sudo ./configure --prefix=/opt/python3
sudo make
sudo make install
sudo ln -s /opt/python3/bin/python3 /usr/bin/python3
$ /usr/bin/python3
Python 3.6.0
Just to make a very brief self-contained answer to compete with the "install from source" suggestions.
The package isn't called python3
but there is one package for each Python3 release.
yum install python36
will get you Python 3.6.
I see all the answers as either asking to compile python3 from code or installing the binary RPM package. Here is another answer to enable EPEL (Extra Packages for Enterprise Linux) and then install python using yum. Steps for RHEL 7.5 (Maipo)
yum install wget –y
wget https://dl.fedoraproject.org/pub/epel/7/x86_64/Packages/e/epel-release-7-11.noarch.rpm
rpm –ivh epel-*.rpm
yum install python36
Also see link
Three steps using Python 3.5 by Software Collections:
sudo yum install centos-release-scl
sudo yum install rh-python35
scl enable rh-python35 bash
Note that sudo is not needed for the last command. Now we can see that python 3 is the default for the current shell:
python --version
Python 3.5.1
Simply skip the last command if you'd rather have Python 2 as the default for the current shell.
Now let's say that your Python 3 scripts give you an error like /usr/bin/env: python3: No such file or directory
. That's because the installation is usually done to an unusual path:
/opt/rh/rh-python35/root/bin/python3
The above would normally be a symlink. If you want python3
to be automatically added to the $PATH
for all users on startup, one way to do this is adding a file like:
sudo vim /etc/profile.d/rh-python35.sh
Which would have something like:
#!/bin/bash
PATH=$PATH:/opt/rh/rh-python35/root/bin/
And now after a reboot, if we do
python3 --version
It should just work. One exception would be an auto-generated user like "jenkins" in a Jenkins server which doesn't have a shell. In that case, manually adding the path to $PATH
in scripts would be one way to go.
Finally, if you're using sudo pip3
to install packages, but it tells you that pip3 cannot be found, it could be that you have a secure_path in /etc/sudoers. Checking with sudo visudo
should confirm that. To temporarily use the standard PATH when running commands you can do, for example:
sudo env "PATH=$PATH" pip3 --version
See this question for more details.
NOTE: There is a newer Python 3.6 by Software Collections, but I wouldn't recommend it at this time, because I had major headaches trying to install Pycurl. For Python 3.5 that isn't an issue because I just did sudo yum install sclo-python35-python-pycurl
which worked out of the box.
If you are on RHEL and want a Red Hat supported Python, use Red Hat Software collections (RHSCL). The EPEL and IUS packages are not supported by Red Hat. Also many of the answers above point to the CentOS software collections. While you can install those, they aren't the Red Hat supported packages for RHEL.
Also, the top voted answer gives bad advice - On RHEL you do not want to change /usr/bin/python
, /usr/bin/python2
because you will likely break yum
and other RHEL admin tools. Take a look at /bin/yum
, it is a Python script that starts with #!/usr/bin/python
. If you compile Python from source, do not do a make install
as root. That will overwrite /usr/bin/python
. If you break yum
it can be difficult to restore your system.
For more info, see How to install Python 3, pip, venv, virtualenv, and pipenv on RHEL on developers.redhat.com. It covers installing and using Python 3 from RHSCL, using Python Virtual Environments, and a number of tips for working with software collections and working with Python on RHEL.
In a nutshell, to install Python 3.6 via Red Hat Software Collections:
$ 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
To use a software collection you have to enable it:
scl enable rh-python36 bash
However if you want Python 3 permanently enabled, you can add the following to your ~/.bashrc and then log out and back in again. Now Python 3 is permanently in your path.
# Add RHSCL Python 3 to my login environment
source scl_source enable rh-python36
Note: once you do that, typing python
now gives you Python 3.6 instead of Python 2.7.
See the above article for all of this and a lot more detail.
yum install python34.x86_64
works if you have epel-release
installed, which this answer explains how to, and I confirmed it worked on RHEL 7.3
$ cat /etc/*-release
NAME="Red Hat Enterprise Linux Server"
VERSION="7.3 (Maipo)
$ type python3
python3 is hashed (/usr/bin/python3)
For RHEL on Amazon Linux, using python3 I had to do :
sudo yum install python34-devel
You can install miniconda (https://conda.io/miniconda.html). That's a bit more than just python 3.7 but the installation is very straightforward and simple.
curl https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -O
sudo yum install bzip2
bash Miniconda3-latest-Linux-x86_64.sh
You'll have to accept the license agreement and choose some options in interactive mode (accept the defaults). I believe it can be also installed silently somehow.