Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Installing Python 2.7 on CentOS 6.5

Installing Python 2.7 on Centos 6.5

Centos 6.* comes with Python 2.6, but we can't just replace it with v2.7 because it's used by the OS internally (apparently) so you will need to install v2.7 (or 3.x, for that matter) along with it. Fortunately, CentOS made this quite painless with their Software Collections Repository

sudo yum update # update yum
sudo yum install centos-release-scl # install SCL 
sudo yum install python27 # install Python 2.7

To use it, you essentially spawn another shell (or script) while enabling the newer version of Python:

scl enable python27 bash

To install additional libraries, you will need to install PIP:

cd /opt/rh/python27/root/usr/bin/ # cd to the directory where SCL installs python
sudo LD_LIBRARY_PATH=$LD_LIBRARY_PATH ./easy_install-2.7 pip

once installed, you can install PIP using pip2.7, e.g.:

sudo LD_LIBRARY_PATH=$LD_LIBRARY_PATH ./pip2.7 install requests 

NOTE: if your username doesn't require root to install software, then LD_LIBRARY_PATH and PATH is set up for you automatically by scl. Also keep in mind that using SCL outside a shell (e.g., cronjobs) isn't quite straightforward. Also, using virtualenv poses a challenge as well.


This comment has been minimized.

Copy link

@codeAshu codeAshu commented Mar 20, 2016

Did you miss yum install -y python27


This comment has been minimized.

Copy link

@crayzeewulf crayzeewulf commented Jun 15, 2016

As @codeAshu mentioned, I had to use slightly modified instructions to install Python 2.7. Please see the updated gist in this fork and the differences here. Feel free to merge it.


This comment has been minimized.

Copy link
Owner Author

@dalegaspi dalegaspi commented Jun 27, 2016

i didn't see these messages (there should be notifications support for gists...) until i randomly wandered into this specific gist...thanks @crayzeewulf...i've merged your changes.


This comment has been minimized.

Copy link

@MarcGodard MarcGodard commented Mar 25, 2017

Getting error: Not a recognized archive type: pip on step sudo LD_LIBRARY_PATH=$LD_LIBRARY_PATH ./easy_install-2.7 pip

However, it is working so it looks like it is already there.


This comment has been minimized.

Copy link

@sonicwong sonicwong commented Jun 19, 2017

same here, got error in last step:

[root@server bin]# sudo LD_LIBRARY_PATH=$LD_LIBRARY_PATH ./easy_install-2.7 pip
/opt/rh/python27/root/usr/bin/python2: error while loading shared libraries: cannot open shared object file: No such file or directory

This comment has been minimized.

Copy link

@cbsdtools cbsdtools commented Sep 14, 2017

I received the same error as @sonicwong


This comment has been minimized.

Copy link

@alanivey alanivey commented Sep 19, 2017

@cbsdtools and @sonicwong -- try this instead:

Because the python27 SCL comes via the centos-release-scl-rh package, you can install pip with: yum install python27-python-pip.

If it may be helpful to know more about how to use SCLs, here is how the command from @sonicwong would be run with all of the proper environment variables set:

scl enable python27 "easy_install-2.7 pip"

scl enable python27 cmd will effectively source the contents of /opt/rh/python27/enable before running the cmd. If the command has arguments, you can wrap it in quotes.

Alternatively, by running scl enable python27 bash, you can jump into a new bash session with PATH, LD_LIBRARY_PATH, MANPATH, XDG_DATA_DIRS, and PKG_CONFIG_PATH to run multiple consecutive commands without the scl enable prefixes .


This comment has been minimized.

Copy link

@JSoet JSoet commented Oct 2, 2017

When running pip I ran into a problem with permissions, it gave me this error any time I tried do any pip command:

$ ./pip2.7 -V
Traceback (most recent call last):
  File "./pip2.7", line 7, in <module>
    from pip import main
  File "/opt/rh/python27/root/usr/lib/python2.7/site-packages/pip/", line 21, in <module>
    from pip._vendor.requests.packages.urllib3.exceptions import DependencyWarning
ImportError: No module named requests.packages.urllib3.exceptions

I found out that this was due to permissions problems on the lib folders. To fix it I had to add the read and execute permissions to the python lib and lib64 folders like:
sudo chmod -R o+rx /opt/rh/python27/root/usr/lib/python2.7/site-packages

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment