有没有办法使用gcloud与python3?

问题描述 投票:21回答:4

我对gcloud和python3有点困惑

我在python3 env中安装了gcloud之后我尝试了Quickstart for Python in the App Engine Flexible Environment的例子。

它说'你需要Google Cloud SDK',所以我安装了SDK。 SDK(包括SDK)之后的所有过程,都需要python2 env。

这是一个问题,是不可能用python3(官方)运行gcloud呢? (SDK和python2与gcloud库是最好的方法吗?)

python google-app-engine google-cloud-platform gcloud
4个回答
14
投票

我通过指定Python 2的路径(我在我的系统上命名为python2)解决了这个问题。

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

我建议将导出添加到.bashrc.zshrc文件中。


7
投票

gcloud-pythongcloud-cli as in Cloud SDK是一些不相关的产品。确实你需要python 2.7.x来运行gcloud-cli,但这并不妨碍你使用python3和gcloud-python库。

如果您安装python 2.7x和3.5的多个版本(例如,您甚至可以使python3默认)只要您将CLOUDSDK_PYTHON环境变量设置为指向python 2.7.x解释器,您应该能够在使用python3时运行gcloud-cli你的项目。

例如,在Windows上,Cloud SDK打包自己的python,它不会与您在系统上可能拥有的任何其他版本冲突。它是gcloud-cli的纯运行时依赖。


0
投票

系统要求明确表示python 2.7.x https://cloud.google.com/sdk/downloads

你为什么要用python3运行gcloud?


0
投票

install.sh内部,它表示支持python3但没有优先级,因为我认为python 2更普遍。这意味着如果你运行macOS,通过echo "export CLOUDSDK_PYTHON=/your/path/to/python3" >> ~/.bash_profile添加一行环境变量将允许gcloud使用任何python3。

如果它不起作用,那么将它指向任何python 2并且只使用python 3为你自己的工作应该解决问题。

# 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
© www.soinside.com 2019 - 2024. All rights reserved.