Is there any way to use gcloud with python3?

后端 未结 5 1348
误落风尘
误落风尘 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条回答
  • 2021-02-05 01:39

    gcloud-python and gcloud-cli as in Cloud SDK are somewhat unrelated products. It is true that you need python 2.7.x to run gcloud-cli, but that does no preclude you from using python3 with gcloud-python library.

    If you install multiple versions of python 2.7x and 3.5 for example (you can even make python3 default) as long as you set CLOUDSDK_PYTHON environment variable to point to python 2.7.x interpreter you should be able to run gcloud-cli while using python3 for your project.

    On Windows for example, Cloud SDK packages its own python which does not conflict with any other version you might have on your system. It is pure runtime dependency for gcloud-cli.

    0 讨论(0)
  • 2021-02-05 01:49

    I worked around this issue by specifying the path to Python 2 (that I named python2 on my system).

    $ export CLOUDSDK_PYTHON=$(which python2)
    $ ./install.sh
    

    I suggest adding the export to your .bashrc or .zshrc file.

    0 讨论(0)
  • 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
    
    0 讨论(0)
  • 2021-02-05 01:55

    The system requirement explicitly said python 2.7.x https://cloud.google.com/sdk/downloads

    why do you want to run gcloud with python3 anyway?

    0 讨论(0)
  • 2021-02-05 01:57

    As of 2019-12-17, version 274.0.0 officially supports Python 3. Release notes:

    Cloud SDK now has GA support for Python 3. Please run gcloud topic startup for:

    • Information on configuring the Python interpreter used by the Cloud SDK.
    • List of tools in the Cloud SDK that still require a Python 2.7 interpreter.
    • List of known issues with Python 3 support.

    (That command shows that dev_appserver and endpointscfg are the exceptions.)

    According to the search order, gcloud will still use Python 2 if it finds it. You can be explicit by setting CLOUDSDK_PYTHON=python3 (or similar) as an environment variable.

    0 讨论(0)
提交回复
热议问题