Is there any way to use gcloud with python3?

后端 未结 5 1352
误落风尘
误落风尘 2021-02-05 01:29

I have a little confused about gcloud with python3

After I installed gcloud in python3 env and I tried to example Quickstart for Python in the App Engine Flexible Enviro

5条回答
  •  梦毁少年i
    2021-02-05 01:51

    Inside the install.sh, it says python3 is supported but not prioritised because python 2 is, I think, more ubiquitous. It means if you are running macOS, add a line of environment variable by echo "export CLOUDSDK_PYTHON=/your/path/to/python3" >> ~/.bash_profile will allow gcloud to use whichever python3 is located.

    If it doesn't work, then point it to whichever python 2 and only use python 3 for your own work should solve the problem.

    # 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
      elif _cloudsdk_which python2.7 >/dev/null; then
        # this is what some OS X versions call their built-in Python
        CLOUDSDK_PYTHON=python2.7
      elif _cloudsdk_which python >/dev/null; then
        # Use unversioned python if it exists.
        CLOUDSDK_PYTHON=python
      elif _cloudsdk_which python3 >/dev/null; then
        # We support python3, but only want to default to it if nothing else is
        # found.
        CLOUDSDK_PYTHON=python3
      else
        # This won't work because it wasn't found above, but at this point this
        # is our best guess for the error message.
        CLOUDSDK_PYTHON=python
      fi
    fi
    

提交回复
热议问题