As of November 2017, the latest Python 3.x versions available in RPMS CentOS/RHEL 7 and Debian 8/9 are 3.4 and
3.5 respectively.
Method Two: Install Python3 from EPEL Repository
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
Method Three: Install Python3 from Software Collections (SCL)
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:
I was asked today to install Python 2.7 on a CentOS based node and I thought I'd take this oportunity to add a companion article
to my
Python 2.6 article.
We're all well aware that CentOS is pretty backwards when it comes to having the latest and greatest sotware
packages and is particularly finicky when it comes to Python since so much of RHEL depends on it.
As a rule, I refuse to rush in and install anything in production that isn't in a manageable package format such as RPM. I need
to be able to predictably reproduce software installs across a large number of nodes.
The following steps will not clobber your default Python 2.4 install and will keep both CentOS and your developers happy.
So, here we go.
Install the dependancies.
sudo yum -y install rpmdevtools tk-devel tcl-devel expat-devel db4-devel \
gdbm-devel sqlite-devel bzip2-devel openssl-devel \
ncurses-devel readline-devel
Setup you RPM build envirnoment.
rpmdev-setuptree
Grab my spec file.
wget https://raw.github.com/nmilford/specfiles/master/python-2.7/python27-2.7.2.spec \
-O ~/rpmbuild/SPECS/python27-2.7.2.spec
wget http://www.python.org/ftp/python/2.7.2/Python-2.7.2.tar.bz2 \
-O ~/rpmbuild/SOURCES/Python-2.7.2.tar.bz2
Build RPM. (FYI, the QA_RPATHS variable tells the rpmbuild to skip some file path errors).
QA_RPATHS=$[ 0x0001|0x0010 ] rpmbuild -bb ~/rpmbuild/SPECS/python-2.7.2.spec
Install the RPMs.
sudo rpm -Uvh ~/rpmbuild/RPMS/x86_64/python27*.rpm
Now on to the the setuptools.
Grab my spec file.
wget https://raw.github.com/nmilford/specfiles/master/python-2.7/python27-setuptools-0.6c11.spec \
-O ~/rpmbuild/SPECS/python27-setuptools-0.6c11.spec
Grab the source.
wget http://pypi.python.org/packages/source/s/setuptools/setuptools-0.6c11.tar.gz \
-O ~/rpmbuild/SOURCES/setuptools-0.6c11.tar.gz
Build the RPMs.
rpmbuild -bb ~/rpmbuild/SPECS/python27-setuptools-0.6c11.spec
Install the RPMs.
sudo rpm -Uvh ~/rpmbuild/RPMS/noarch/python27-setuptools-0.6c11-milford.noarch.rpm
Now, we'll install MySQL-python as an example.
Grab the mysql-dev package
yum -y install mysql-devel
Grab, build and install the MySQL-python package.
curl http://superb-sea2.dl.sourceforge.net/project/mysql-python/mysql-python/1.2.3/MySQL-python-1.2.3.tar.gz | tar zxv
cd MySQL-python-1.2.3
python2.7 setup.py build
python2.7 setup.py install
Like with the previous Python 2.6 article, note how I called the script explicitly using the following python binary: /usr/bin/python2.7
Now we're good to give it the old test thus:
python2.7 -c "import MySQLdb"
If it doesn't puke out some error message, you're all set.
Happy pythoning.
Copyright © 1996-2021 by Softpanorama Society. www.softpanorama.org
was initially created as a service to the (now defunct) UN Sustainable Development Networking Programme (SDNP)
without any remuneration. This document is an industrial compilation designed and created exclusively
for educational use and is distributed under the Softpanorama Content License.
Original materials copyright belong
to respective owners. Quotes are made for educational purposes only
in compliance with the fair use doctrine.
FAIR USE NOTICE This site contains
copyrighted material the use of which has not always been specifically
authorized by the copyright owner. We are making such material available
to advance understanding of computer science, IT technology, economic, scientific, and social
issues. We believe this constitutes a 'fair use' of any such
copyrighted material as provided by section 107 of the US Copyright Law according to which
such material can be distributed without profit exclusively for research and educational purposes.
This is a Spartan WHYFF (We Help You For Free)
site written by people for whom English is not a native language. Grammar and spelling errors should
be expected. The site contain some broken links as it develops like a living tree...
Disclaimer:
The statements, views and opinions presented on this web page are those of the author (or
referenced source) and are
not endorsed by, nor do they necessarily reflect, the opinions of the Softpanorama society. We do not warrant the correctness
of the information provided or its fitness for any purpose. The site uses AdSense so you need to be aware of Google privacy policy. You you do not want to be
tracked by Google please disable Javascript for this site. This site is perfectly usable without
Javascript.