2
votes

I'm trying to install gcloud on my EC2 server running Amazon Linux 4.14.47-56.37 64bits, in interactive mode running the following command :

curl https://sdk.cloud.google.com | bash

The files download correctly, but the install then fails with the following Traceback :

  File "/home/ec2-user/google-cloud-sdk/bin/bootstrapping/install.py", line 12, in <module>
    import bootstrapping
  File "/home/ec2-user/google-cloud-sdk/bin/bootstrapping/bootstrapping.py", line 32, in <module>
    import setup  # pylint:disable=g-import-not-at-top
  File "/home/ec2-user/google-cloud-sdk/bin/bootstrapping/setup.py", line 55, in <module>
    from googlecloudsdk.core import properties
  File "/home/ec2-user/google-cloud-sdk/lib/googlecloudsdk/core/properties.py", line 291
    self.__sections = {section.name: section for section in sections}
                                               ^
SyntaxError: invalid syntax

Any idea why this for is causing issues?

I am running python 2.7 (2.7.14) as recommended by Google.

5
It looks like the installation script is finding a python version that does not support dictionary comprehension. You may have an old python installation (2.6 or below) that's getting found before the 2.7. What do you see when you run python2 --version? or even python --version? - Abdou
That 4.14.47-56.37 is the kernel version; which distro version are you using? Is it Amazon Linux 2 LTS? If you tell us that, we can at least look up what versions of everything it includes, instead of having to guess. Also, did you get Python 2.7 builtin, from Amazon Linux Extras, or from a non-Amazon repo? - abarnert
I've tried that with Python 2.7.13 and worked. If you execute python --version and which python does it point to the correct python version? - Miguel Ortiz
@Abdou and Miguel Ortiz : python --version returns 2.7.14, and which python does point to this one (/usr/bin/python), but python2 --version returns 2.6.9. Can this cause issues? Edit : Yes it can. I removed python 2.6 and the install completed successfully. - Dino
@abarnert : "Amazon Linux AMI release 2018.03", is that the distro? It's not Amazon Linux 2. Got python with yum, package python27 (this version of Amazon Linux has yum built in). - Dino

5 Answers

2
votes

On top of python 2.7 installed on the "python" command, I also had python 2.6 installed on the "python2" command. Uninstalling python 2.6 solved the issue, Google Cloud install went through without issue on the next try.

2
votes

You locally update the install.sh file to use python2.7 instead of python2. This worked for me

1
votes

Setup yum repo:

# Update YUM with Cloud SDK repo information:
sudo tee -a /etc/yum.repos.d/google-cloud-sdk.repo << EOM
[google-cloud-sdk]
name=Google Cloud SDK
baseurl=https://packages.cloud.google.com/yum/repos/cloud-sdk-el7-x86_64
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg
       https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg
EOM
# The indentation for the 2nd line of gpgkey is important.

Install yum downloader and download the rpm, then install with "--nodeps":

yum install yum-utils
yumdownloader google-cloud-sdk-231.0.0-1.el7.noarch
mv 23873bd6e8459ba6e70e96eb8f03f6ac03cd707ce3c80baa8264c714e030c915-google-cloud-sdk-231.0.0-1.el7.noarch.rpm /usr/local/src/google-cloud-sdk-231.0.0-1.el7.noarch
rpm -ivh --nodeps /usr/local/src/google-cloud-sdk-231.0.0-1.el7.noarch
1
votes

In case someone meets this problem again, and if you do not want to uninstall python 2.6 or to modify install.sh, here is a procedure that worked for me on an ec2 instance :

open a new terminal and type :

curl https://sdk.cloud.google.com | bash

The install should not work as CLOUDSDK_PYTHON=python2 by default, which leads to Python 2.6. To correct this, enter this command :

export CLOUDSDK_PYTHON=python

this links CLOUDSDK_PYTHON to Python 3.6

then

bash google-cloud-sdk/install.sh

and finally

./google-cloud-sdk/bin/gcloud init

Once this is done, you can use any gcloud or gsutil command by doing this :

./google-cloud-sdk/bin/gcloud <your gcloud command>
./google-cloud-sdk/bin/gsutil <your gsutil command>

For example, in order to copy a folder from a gs bucket to your ec2 instance :

./google-cloud-sdk/bin/gsutil -m cp -r gs://<bucket_name>/path/to/folder /path/on/your/ec2/instance

the -m option allows fast transfer (I could transfer with an average speed of 81 MiB/s with this option)

Hope this helps !

0
votes

This solved issue:

export CLOUDSDK_PYTHON=python