gcloud command not found - while installing Google Cloud SDK

后端 未结 28 1206
忘掉有多难
忘掉有多难 2020-12-07 13:43

I am on a mac and am trying to install the Google Cloud SDK (including the gcloud command line utility) using this command in terminal

curl https://sdk.cloud         


        
28条回答
  •  南笙
    南笙 (楼主)
    2020-12-07 14:11

    I had a very different story here that turned out to be caused by my Python virtual environments.

    Somewhere in the middle of running curl https://sdk.cloud.google.com | bash, I was getting error:

    ~/google-cloud-sdk/install.sh
    Welcome to the Google Cloud SDK!
    pyenv: python2: command not found
    
    The `python2' command exists in these Python versions:
      2.7.14
      miniconda2-latest
    

    solution I've modified google-cloud-sdk/install.sh script:

    # if CLOUDSDK_PYTHON is empty
    if [ -z "$CLOUDSDK_PYTHON" ]; then
      # if python2 exists then plain python may point to a version != 2
      #if _cloudsdk_which python2 >/dev/null; then
      #  CLOUDSDK_PYTHON=python2
      if _cloudsdk_which python2.7 >/dev/null; then
        # this is what some OS X versions call their built-in Python
        CLOUDSDK_PYTHON=python2.7
    

    and was able to run the installation successfully. However, I still need to activate my pyenv that has python2 command to run gcloud.

    why so

    If you look at the google-cloud-sdk/install.sh script, you'll see that it's actually checking for versions of Python in a very brute manner:

    if [ -z "$CLOUDSDK_PYTHON" ]; then
      # if python2 exists then plain python may point to a version != 2
      if _cloudsdk_which python2 >/dev/null; then
        CLOUDSDK_PYTHON=python2
    
    

    However, on my machine python2 doesn't point to Python binary, neither returns null. So the installation crashed.

提交回复
热议问题