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.
@cbsdtools and @sonicwong -- try this instead:
Because the
python27
SCL comes via thecentos-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 cmd
will effectivelysource
the contents of/opt/rh/python27/enable
before running thecmd
. 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 withPATH
,LD_LIBRARY_PATH
,MANPATH
,XDG_DATA_DIRS
, andPKG_CONFIG_PATH
to run multiple consecutive commands without thescl enable
prefixes .