google-cloud-sdk installation not finding right Python 2.7 version in CentOS /usr/local/bin

santoshthota picture santoshthota · Mar 28, 2017 · Viewed 7.9k times · Source

Our server OS is CentOS 6.8, I was trying to install google-cloud-sdk, even though I installed

python 2.7 in /usr/local/bin

, it is still looking at old version of

python 2.6 in /usr/bin

. I tried giving export PATH=/usr/local/bin:$PATH to first look at /usr/local/bin than /usr/bin but still the problem persists. please suggest a way to fix.

Answer

brian picture brian · Apr 8, 2017

The way I have solved this (and I know it works) is to first install Python 2.7 in whatever way you'd like, then install pip using Python 2.7 which will give you pip2.7. You can then use pip2.7 to install the google_compute_engine module so that it ends up in the right modules folder.

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

# install the gcloud module
pip2.7 install google_compute_engine

You can then add this to your $HOME/.bashrc

export CLOUDSDK_PYTHON=/usr/local/bin/python2.7

This is the best repeatable way I know of