14

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.

ramulin
  • 293
  • 3
  • 7
calbear47
  • 1,060
  • 2
  • 18
  • 38
  • 1
    Could it be that the env var is expected to point to the actual python executable (i.e. the actual `C:\Python27\python.exe` file - or whatever its name is - can't really check as I'm not using windows), not just the directory where the executable is located? – Dan Cornilescu Nov 21 '16 at 20:16
  • @DanCornilescu Yeah, I just checked that as well. Still received the same error message. -> "install.sh: line 128: $'C:\\Python27\\python.exe\r': command not found". – calbear47 Nov 21 '16 at 20:24
  • How are you setting the env var? I'd just run `SET CLOUDSDK_PYTHON=C:\Python27\python.exe` in the terminal where the installation script will later be executed. – Dan Cornilescu Nov 21 '16 at 20:33

6 Answers6

34

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
Phillip Kigenyi
  • 1,359
  • 14
  • 21
6

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

EvanL00
  • 370
  • 3
  • 13
4

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

ramulin
  • 293
  • 3
  • 7
3

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.

calbear47
  • 1,060
  • 2
  • 18
  • 38
1

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.

Baum mit Augen
  • 49,044
  • 25
  • 144
  • 182
1

Add CLOUDSDK_PYTHON in your system variable and assign it the value of your python.exe file as shown below : enter image description here

Restart your services so that the change can take effect.

Shivam Bharadwaj
  • 1,864
  • 21
  • 23