Skip to content

Instantly share code, notes, and snippets.

@dalegaspi
Last active September 9, 2021 05:29
Show Gist options
  • Star 60 You must be signed in to star a gist
  • Fork 17 You must be signed in to fork a gist
  • Save dalegaspi/dec44117fa5e7597a559 to your computer and use it in GitHub Desktop.
Save dalegaspi/dec44117fa5e7597a559 to your computer and use it in GitHub Desktop.
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.

@dvshelley
Copy link

For this error: Error: python2.7: error while loading shared libraries: libpython2.7.so.1.0: cannot open shared object file: No such file or directory

Follow the answer here: https://stackoverflow.com/questions/20842732/libpython2-7-so-1-0-cannot-open-shared-object-file-no-such-file-or-directory

Try to find file libpython2.7.so.1.0:
locate libpython2.7.so.1.0
In my case, it show out put:
	/opt/rh/python27/root/usr/lib64/libpython2.7.so.1.0
Then paste line /opt/rh/python27/root/usr/lib64 to file /etc/ld.so.conf
And run ldconfig

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