Python Error on Google Cloud Install. How do I properly set the environment variable?

25,739

Solution 1

I had the same issue when the sdk was pointing to the virtualenv python. I solved it by using the default python2.7 in Ubuntu

Type this in termimal

export CLOUDSDK_PYTHON=/usr/bin/python

Solution 2

This is because the gcloud.bat command can't find the right python.exe. I solved the problem by simply put

SET CLOUDSDK_PYTHON=pathWherePythonexeLocate

into the file cloud_env.bat in google Cloud SDK file folder. And revise the install.sh won't help, because it do nothing to the env since the install.sh was run when you first install gcloud sdk. and sdk only support python2.7, so the path is pointed to python2.7, such as C:\myname\soft\python27.exe

Solution 3

Two configurations fixed my issue with this.

  1. My laptop runs Windows 10, and I found that there was file:
C:\Users\<myusername>\AppData\Local\Microsoft\WindowsApps\python.exe

That file is size 0 Kb. This directory was ahead of the C:\Python27 path where Python was actually installed. I tried moving C:\Python27 higher in the Path string, but this did not work.

While I did not reboot, I did open a fresh CMD window and confirmed that C:\Python27 was higher in the path than the AppData directory. Still did not work.

  1. When I changed the CLOUDSDK_PYTHON path, just the "path" is not enough. The FULL path must be provided, including the executable name.

Making these two changes enabled gCloud to work.

Of course just as I finished typing the above, I saw email from Google regarding the change below.

IMPORTANT NOTE Python 2.7 will no longer get updates after Jan 1, 2020, so gcloud as of v274.0.0 will run with Python 3x. I can't find a web page announcing this, but there is mention of the change on this page: https://cloud.google.com/sdk/docs/quickstart-linux

Solution 4

The way I solved this was simply by downloading the Versioned SDK instead of the Interactive SDK. I manually added gcloud to my path, and all worked. I still don't know why the interactive download was not finding Python from my systems path, but the Versioned SDK without Python worked.

Thanks for the tips @DanCornilescu.

Solution 5

if you are facing the issue on 274.0.0 on Windows,

This is being tracked in the public bug https://issuetracker.google.com/issues/146458519

An employee replied:

We have a patch for two files that are causing these problems. These apply in two cases (both on Windows): 1. A new install fails, or 2. You are unable to run gcloud after performing a components update.

For case # 1, please download the attached file install.bat, and copy it to the location where you have attempted to install gcloud, e.g. C:\Program Files (x86)\Google\Cloud SDK\google-cloud-sdk. Then run it, e.g.

> cd C:\Program Files (x86)\Google\Cloud SDK\google-cloud-sdk
> .\install.bat

For both cases #1 and #2, download the attached file gcloud.cmd, and copy it to the bin directory under your gcloud installation, e.g. C:\Program Files (x86)\Google\Cloud SDK\google-cloud-sdk\bin. When prompted to replace the previous copy, type Yes. This should allow you to run gcloud without being prompted to set CLOUDSDK_PYTHON.

The files are attached in the public bug tracker.

Share:
25,739
calbear47
Author by

calbear47

Updated on October 27, 2021

Comments

  • calbear47
    calbear47 over 2 years

    I am trying to install the Google Cloud SDK on my Windows machine. I have Python 2.7 currently installed on this machine, and it's located in the System Variables Path like this -> C:\Python27\;

    I am getting this error during installation:

    ERROR: gcloud failed to load: DLL load failed: %1 is not a valid Win32 application.

    The error message also prompts me to check the Python executable by saying:

    If it is not, please set the CLOUDSDK_PYTHON environment variable to point to a working Python 2.7 executable.

    So, I'm trying to set the CLOUDSDK_PYTHON environment variable in the install.sh shell script...But nothing is working. Here is the code from that file:

    echo Welcome to the Google Cloud SDK!
    
    if [ -z "$CLOUDSDK_PYTHON" ]; then
     if [ -z "$(which python)" ]; then
      echo
      echo "To use the Google Cloud SDK, you must have Python installed and on your PATH."
      echo "As an alternative, you may also set the CLOUDSDK_PYTHON environment variable"
      echo "to the location of your Python executable."
      exit 1
     fi
     CLOUDSDK_PYTHON="python"
    fi
    

    I have tried python2.7, and the path to the executable, C:\Python27, but I'm getting this error when I try to run the script with those variables:

    install.sh: line 128: $'python\r': command not found
    

    I found this stack question, but none of the solutions worked for me. Any help would be great appreciated.