Last updated on October 19, 2020 by Dan Nanni
python3
on CentOS system. However, my CentOS only has python
2.X installed, but not python
3.X. How can I install python3
on CentOS?
As of CentOS 7, the default Python version still remains python
2.7, and python3
is not available in base repositories. If you need to use python3
as part of Python application dependency, there are several ways to install python3
on CentOS.
You can always build python3
from its source manually. Since you can choose the version of python3
to install, this is the surest way to meet Python dependency requirement.
Here is how you can build and install python3
from the source.
First, install minimum necessary tools:
$ sudo yum install yum-utils
Then using yum-builddep
, set up a necessary build environment for python3
and install missing dependencies. The following command will automatically take care of that.
$ sudo yum-builddep python
Now download the latest python3
(e.g., python
3.5) from https://www.python.org/ftp/python/
$ curl -O https://www.python.org/ftp/python/3.5.0/Python-3.5.0.tgz
Finally, build and install python3
as follows. The default installation directory is /usr/local
. If you want to change this to some other directory, pass --prefix=/alternative/path
parameter to configure
before running make
.
$ tar xf Python-3.5.0.tgz $ cd Python-3.5.0 $ ./configure $ make $ sudo make install
This will install python3
, pip3
, setuptools
as well as python3
libraries on your CentOS system.
$ python3 --version
Python 3.5.0
If you want to use python3
as your default Python interpreter, you can define the following alias in your .bashrc
.
alias python='/usr/local/bin/python3.5'
The latest EPEL 7 repository offers python3
(python
3.4 to be exact). Thus if you are using CentOS 7 or later, you can easily install python3
by enabling EPEL repository as follows.
$ sudo yum install epel-release
Then install python
3.4 and its libraries using yum
:
$ sudo yum install python34
Note that this will not install matching pip
. To install pip
and setuptools
, you need to install them separately as follows.
$ curl -O https://bootstrap.pypa.io/get-pip.py $ sudo /usr/bin/python3.4 get-pip.py
Another way to install python3
is via enabling Software Collections (SCL) repository. The SCL repository is available for CentOS 6.5 or later, and the latest SCL offers python
3.3. Once you enable the SCL repository, go ahead and install python3
as follows.
$ sudo yum install python33
To use python3
from the SCL, you need to enable python3
on a per-command basis as follows.
$ scl enable python33 <command>
You can also invoke a bash
shell with python3
enabled as the default Python interpreter:
$ scl enable python33 bash
This website is made possible by minimal ads and your gracious donation via PayPal or credit card
Please note that this article is published by Xmodulo.com under a Creative Commons Attribution-ShareAlike 3.0 Unported License. If you would like to use the whole or any part of this article, you need to cite this web page at Xmodulo.com as the original source.
Xmodulo © 2021 ‒ About ‒ Write for Us ‒ Feed ‒ Powered by DigitalOcean