60

Can someone provide the steps needed to install python version 2.7 on SUSE and RedHat? It version that is on there is like 2.4 and I need to have it at at least 2.6 to make my script work. So after the install, I can type Python in a xTerm and get the Python 2.7 command line interface.

Lev Levitsky
  • 63,701
  • 20
  • 147
  • 175
Dag
  • 1,101
  • 4
  • 11
  • 13

11 Answers11

127

Instructions to download source and install:

https://www.python.org/download/

NOTE: You should check for the latest version of python 2.7.x, as it gets updated frequently. Currently (Oct 2017), the latest version is 2.7.14 though this comment will get old and new versions likely will be released every 6 months or so.

wget https://www.python.org/ftp/python/2.7.14/Python-2.7.14.tgz # Download
tar xvfz Python-2.7.14.tgz # unzip
cd Python-2.7.14 # go into directory
./configure
make # build
su # or 'sudo su' if there is no root user
make altinstall

(EDIT: make install -> make altinstall per Ignacio's comment).

dr jimbob
  • 17,259
  • 7
  • 59
  • 81
  • so I just type those commands into a xterm window, and I am good to go? – Dag Nov 10 '10 at 21:54
  • 9
    +1 for showing the actual commands (dear to any linux person) to untar and 'install' software from source :) – g19fanatic Nov 10 '10 at 21:55
  • 52
    `make install` will damage the system Python. Use `make altinstall` instead. – Ignacio Vazquez-Abrams Nov 10 '10 at 21:57
  • @Dag: that will download the source for python 2.7, untar it, build it, install it. seeing as you already have python(2.4) on your path, it 'might' mess up just loading the python intrep from xterm by just typing `python` so you still need to add the proper `path/to/python2.7/bin/` to your system path – g19fanatic Nov 10 '10 at 21:57
  • OK, so I don't want to mess up the server, but I need to run with at least 2.6 and why not make it 2.7 So from the above commands, what is it that I need to change to make this work? Not very familiar with linux, but I can follow directions. – Dag Nov 10 '10 at 22:06
  • OK, I did this one except the last step was make altinstall. That seemed to work – Dag Nov 11 '10 at 00:11
  • 1
    How can the system path be change so that python 2.7.* is the default one? – Marco Jan 27 '14 at 16:08
  • On fresh machine w/o any dev deps, you may need to also do `sudo yum install automake gcc` – NG. May 21 '14 at 19:37
  • 1
    how do you make the python 27 install to your system path? So that when I type "python" in terminal or go to install ipython it recognises 2.7. I am on redhat 6.5 and when I type "python --version" I get 2.7.5. But when I sudo python setup.py install I get an error (need 2.7 or above). – yoshiserry Nov 24 '14 at 22:16
  • Thank you. The suggested is well and everything went fine. But, after 'altinstall' still python gives the old version. Can you kindly let me know where exactly it does install/upgrade? – Vijay Feb 21 '15 at 17:00
  • As somebody else already pointed here, [software collections](http://developerblog.redhat.com/2013/01/28/software-collections-on-red-hat-enterprise-linux/) are much better solution there. – marbu May 25 '15 at 05:07
  • 1
    What if I already did ```make install```? How do I fix? Thanks! – xxks-kkk Apr 07 '16 at 06:37
  • @Jerry pray. Most of default tools, like the regular apt-get relies on the system python. I did that once into an vps and the only way to revert was get backup back. There's no real way to do that unless you really know howto rollback inodes and other hard stuff. In short: pray. – m3nda Jan 02 '17 at 06:08
  • @yoshiserry i think that the best approach is to create an alias at user level, meaning at your ./~bashrc file. When you launch things like apt-get as sudo, it will use the python old-system binary, but when you put python on your user's console you'll get the one you created at alias. – m3nda Jan 02 '17 at 06:15
  • currently https://www.python.org/ftp/python/2.7.11/Python-2.7.11.tgz and this is a 2015 release – rleir Oct 31 '17 at 15:23
  • @rleir - It's actually 2.7.14 as the latest release. I don't normally make an attempt to update it, but noticed python.org now supports https so worth an update. – dr jimbob Oct 31 '17 at 15:31
  • @marbu mentioned "software solutions" as a possible solution for this. It's hard to find resources about this that aren't retired or deprecated. Here's one, although any details about using it specifically for Python2.7 are not prominent: https://www.softwarecollections.org/en/docs/guide/ – Jonathan Hartley Nov 10 '17 at 15:19
13

RHEL 6.2 using (had Python 2.6, i need Python 2.7.3) So:

$ sudo sh -c 'wget -qO- http://people.redhat.com/bkabrda/scl_python27.repo >> /etc/yum.repos.d/scl.repo'

$ yum search python27
Loaded plugins: amazon-id, rhui-lb, security
scl_python27                                                                                                                                      | 2.9 kB     00:00     
scl_python27/primary_db                                                                                                                           |  38 kB     00:00     
========================================================================= N/S Matched: python27 =========================================================================
python27.i686 : Package that installs python27
python27.x86_64 : Package that installs python27
python27-expat-debuginfo.i686 : Debug information for package python27-expat
python27-expat-debuginfo.x86_64 : Debug information for package python27-expat
python27-python-coverage-debuginfo.i686 : Debug information for package python27-python-coverage
python27-python-coverage-debuginfo.x86_64 : Debug information for package python27-python-coverage
python27-python-debuginfo.i686 : Debug information for package python27-python
python27-python-debuginfo.x86_64 : Debug information for package python27-python
python27-python-markupsafe-debuginfo.i686 : Debug information for package python27-python-markupsafe
python27-python-markupsafe-debuginfo.x86_64 : Debug information for package python27-python-markupsafe
python27-python-simplejson-debuginfo.i686 : Debug information for package python27-python-simplejson
python27-python-simplejson-debuginfo.x86_64 : Debug information for package python27-python-simplejson
python27-python-sqlalchemy-debuginfo.i686 : Debug information for package python27-python-sqlalchemy
python27-python-sqlalchemy-debuginfo.x86_64 : Debug information for package python27-python-sqlalchemy
python27-runtime.i686 : Package that handles python27 Software Collection.
python27-runtime.x86_64 : Package that handles python27 Software Collection.
python27-babel.noarch : Tools for internationalizing Python applications
python27-build.i686 : Package shipping basic build configuration
python27-build.x86_64 : Package shipping basic build configuration
python27-expat.i686 : An XML parser library
python27-expat.x86_64 : An XML parser library
python27-expat-devel.i686 : Libraries and header files to develop applications using expat
python27-expat-devel.x86_64 : Libraries and header files to develop applications using expat
python27-expat-static.i686 : expat XML parser static library
python27-expat-static.x86_64 : expat XML parser static library
python27-python.i686 : An interpreted, interactive, object-oriented programming language
python27-python.x86_64 : An interpreted, interactive, object-oriented programming language
python27-python-babel.noarch : Library for internationalizing Python applications
python27-python-coverage.i686 : Code coverage testing module for Python
python27-python-coverage.x86_64 : Code coverage testing module for Python
python27-python-debug.i686 : Debug version of the Python runtime
python27-python-debug.x86_64 : Debug version of the Python runtime
python27-python-devel.i686 : The libraries and header files needed for Python development
python27-python-devel.x86_64 : The libraries and header files needed for Python development
python27-python-docutils.noarch : System for processing plaintext documentation
python27-python-jinja2.noarch : General purpose template engine
python27-python-libs.i686 : Runtime libraries for Python
python27-python-libs.x86_64 : Runtime libraries for Python
python27-python-markupsafe.i686 : Implements a XML/HTML/XHTML Markup safe string for Python
python27-python-markupsafe.x86_64 : Implements a XML/HTML/XHTML Markup safe string for Python
python27-python-nose.noarch : Discovery-based unittest extension for Python
python27-python-nose-docs.noarch : Nose Documentation
python27-python-pygments.noarch : Syntax highlighting engine written in Python
python27-python-setuptools.noarch : Easily build and distribute Python packages
python27-python-simplejson.i686 : Simple, fast, extensible JSON encoder/decoder for Python
python27-python-simplejson.x86_64 : Simple, fast, extensible JSON encoder/decoder for Python
python27-python-sphinx.noarch : Python documentation generator
python27-python-sphinx-doc.noarch : Documentation for python-sphinx
python27-python-sqlalchemy.i686 : Modular and flexible ORM library for python
python27-python-sqlalchemy.x86_64 : Modular and flexible ORM library for python
python27-python-test.i686 : The test modules from the main python package
python27-python-test.x86_64 : The test modules from the main python package
python27-python-tools.i686 : A collection of development tools included with Python
python27-python-tools.x86_64 : A collection of development tools included with Python
python27-python-virtualenv.noarch : Tool to create isolated Python environments
python27-python-werkzeug.noarch : The Swiss Army knife of Python web development
python27-python-werkzeug-doc.noarch : Documentation for python-werkzeug
python27-tkinter.i686 : A graphical user interface for the Python scripting language
python27-tkinter.x86_64 : A graphical user interface for the Python scripting language

  Name and summary matches only, use "search all" for everything.

EDIT:

CentOS 6.x: http://dev.centos.org/centos/6/SCL/x86_64/python27/

$ sudo sh -c 'wget -qO- http://dev.centos.org/centos/6/SCL/scl.repo >> /etc/yum.repos.d/scl.repo'
$ scl enable python27 'python --version'
python 2.7.5
$ scl enable python27 bash
$ python --version
Python 2.7.5
  • 1
    What does `scl` stand for? Is this repo stable? Like EPEL, does it promise not to interfere with the default system packages? – Stefan Lasiewski Jun 10 '13 at 18:39
  • 5
    @StefanLasiewski: `scl` stands for [Software Collections](https://fedorahosted.org/SoftwareCollections/), and yes they do make that promise explicitly (it's actually their very purpose). [Introduction](http://developerblog.redhat.com/2013/01/28/software-collections-on-red-hat-enterprise-linux/). [Guide](https://docs.fedoraproject.org/en-US/Fedora_Contributor_Documentation/1/html-single/Software_Collections_Guide/index.html). The repository suggested by YumYumYum is maintained by a [Red Hat engineer](https://fedoraproject.org/w/index.php?title=User:Bkabrda&oldid=318815) and targets RHEL6. – tne Nov 20 '13 at 14:22
8

The accepted answer by dr jimbob (using make altinstall) got me most of the way there, with python2.7 in /usr/local/bin but I also needed to install some third party modules. The nice thing is that easy_install gets its installation locations from the version of Python you are running, but I found I still needed to install easy_install for Python 2.7 otherwise I would get ImportError: No module named pkg_resources. So I did this:

wget http://pypi.python.org/packages/2.7/s/setuptools/setuptools-0.6c11-py2.7.egg
sudo -i
export PATH=$PATH:/usr/local/bin
sh setuptools-0.6c11-py2.7.egg
exit

Now I have easy_install and easy_install-2.7 in /usr/local/bin and the former overrides my system's 2.6 version of easy_install, so I removed it:

sudo rm /usr/local/bin/easy_install

Now I can install libraries for the 2.7 version of Python like this:

sudo /usr/local/bin/easy_install-2.7 numpy
Rob Fisher
  • 945
  • 1
  • 9
  • 20
  • 4
    I had to do `yum -y install zlib-devel` in order to get setuptools to install. – par Aug 28 '12 at 22:55
3

To install Python 2.7.2 use this script - https://github.com/bngsudheer/bangadmin/blob/master/linux/centos/6/x86_64/build-python-27.sh

It also makes sure you get sqlite and readline support.

Sudheer
  • 710
  • 6
  • 25
2

Execute the below commands to make yum work as well as python2.7

yum groupinstall -y development
yum groupinstall -y 'development tools'
yum install -y zlib-dev openssl-devel wget sqlite-devel bzip2-devel
yum -y install gcc gcc-c++ numpy python-devel scipy git boost*
yum install -y *lapack*
yum install -y gcc gcc-c++ make bison flex autoconf libtool memcached libevent libevent-devel uuidd libuuid-devel  boost boost-devel libcurl-dev libcurl curl gperf mysql-devel

cd
mkdir srk
cd srk 
wget http://www.python.org/ftp/python/2.7.6/Python-2.7.6.tar.xz
yum install xz-libs
xz -d Python-2.7.6.tar.xz
tar -xvf Python-2.7.6.tar
cd Python-2.7.6
./configure --prefix=/usr/local
make
make altinstall



echo "export PATH="/usr/local/bin:$PATH"" >> /etc/profile
source /etc/profile
mv /usr/bin/python /usr/bin/python.bak
update-alternatives --install /usr/bin/python python /usr/bin/python2.6 1
update-alternatives --install /usr/bin/python python /usr/local/bin/python2.7 2
update-alternatives --config python
sed -i "s/python/python2.6/g" /usr/bin/yum
Shahrukh Khan
  • 316
  • 1
  • 3
  • 15
  • using altinstall does install it on `/usr/local` by design. the other way would be use `./configure --prefix=/usr/local` then just make install. the system python will remain untouched in both cases. – m3nda Jan 02 '17 at 08:17
2

You have to leave Python 2.4 installed on RHEL/Centos; otherwise, tools start breaking. You can do a dual-install, though; I talk about this here:

http://thebuild.com/blog/2009/10/17/wordpress-to-djangopostgresql-part-3-installing-apache-python-2-6-psycopg2-and-mod_wsgi/

The post is about 2.6, but applies equally to 2.7.

Christophe
  • 2,052
  • 1
  • 19
  • 24
  • 1
    Also this link would work when installing python on RH, leaving python 2.4 as it is: http://tecadmin.net/install-python-2-7-on-centos-rhel/ – Leonard Saers Jul 21 '15 at 15:08
1

Great thing about linux, you're still able to download the source and on most systems have all of the tools to compile the version yourself.

In order to get a python cli from xterm just by typing python, the python bin directory must be in your system path variable (Red Hat example, Suse example)

g19fanatic
  • 10,567
  • 6
  • 33
  • 63
1

If you can live with 2.6, EPEL has it for RHEL 5 in the python26 package, although you will need to use python2.6 to invoke it since the system will still need python to be 2.4 in order to run.

Ignacio Vazquez-Abrams
  • 776,304
  • 153
  • 1,341
  • 1,358
0

If you need pip and setup tool , please install openssl and opessl-devl before making python2.7

 yum install openssl-devel

Then follow https://stackoverflow.com/a/4149444/429476

Then https://pypi.python.org/pypi/setuptools

wget https://bootstrap.pypa.io/ez_setup.py
python2.7 ez_setup.py

Then to install pip

wget https://bootstrap.pypa.io/get-pip.py
python2.7 get-pip.py

Then to install other packages pip2.7 install package_name

Community
  • 1
  • 1
Alex Punnen
  • 5,287
  • 3
  • 59
  • 71
0

If you want to install Python 2.7 on Oracle Linux, you can proceed as follows:

Enable the Software Collection in /etc/yum.repos.d/public-yum-ol6.repo.

vim /etc/yum.repos.d/public-yum-ol6.repo

[public_ol6_software_collections] 
name=Software Collection Library release 1.2 packages for Oracle Linux 6 
(x86_64) 
baseurl=[http://yum.oracle.com/repo/OracleLinux/OL6/SoftwareCollections12/x86_64/][1] 
    gpgkey=file:[///etc/pki/rpm-gpg/RPM-GPG-KEY-oracle][2] 
    gpgcheck=1 
    enabled=1 <==============change from 0 to 1

After making this change to the yum repository you can simply run the yum command to install the Python:

yum install gcc libffi libffi-devel python27 python27-python-devel openssl-devel python27-MySQL-python

edit bash_profile with follow variables:

vim ~/.bash_profile
PATH=$PATH:$HOME/bin:/opt/rh/python27/root/usr/bin export PATH
LD_LIBRARY_PATH=/opt/rh/python27/root/usr/lib64 export LD_LIBRARY_PATH
PKG_CONFIG_PATH=/opt/rh/python27/root/usr/lib64/pkgconfig export PKG_CONFIG_PATH

Now you can use python2.7 and pip for install Python modules:

/opt/rh/python27/root/usr/bin/pip install pynacl
/opt/rh/python27/root/usr/bin/python2.7 --version
Bugs
  • 4,491
  • 9
  • 32
  • 41
Adriano P
  • 1,041
  • 7
  • 4
0

If you get an error when at the ./configure stage that says

configure: error: in `/home//Downloads/Python-2.7.14': configure: error: no acceptable C compiler found in $PATH

then try this.

no acceptable C compiler found in $PATH when installing python

nmarchini
  • 131
  • 4