在 Windows 7 上安装 Google Cloud SDK 时出错

Error installing Google Cloud SDK on Windows 7

我最近在 Windows 7 上安装了 Python 3.5 64 位。现在在尝试安装 Google Cloud SDK 时出现以下错误:

Output folder: C:\Program Files (x86)\Google\Cloud SDK
Downloading Google Cloud SDK core.
Extracting Google Cloud SDK core.
Create Google Cloud SDK bat file: C:\Program Files (x86)\Google\Cloud SDK\cloud_env.bat
Installing components.
Welcome to the Google Cloud SDK!
  File "C:\Python\Lib\site.py", line 176
    file=sys.stderr)
        ^
SyntaxError: invalid syntax
  File "C:\Python\Lib\site.py", line 176
    file=sys.stderr)
        ^
SyntaxError: invalid syntax
Failed to install.

我没有修改任何 Python 库文件。

我认为 Google Cloud SDK 不能 运行 Python 3(system requirements 声明 Python 2.7.x 是必需的)。

windows GUI 安装程序的第 5 步中有一个 'bundled python' 选项(在您选择安装路径后)如果您需要快速安装一个 Python 2.7 只是为了这些工具。

]

请注意,只有 CLI 工具需要 Python 2.7。 python API google-api-python-client [1] and gcloud-python [2] 将与 python 3.5 一起使用。所以根据你在做什么,你仍然可以在你的项目中使用 Python 3。

[1] 来自 google-api-python-客户端 README.md

Python 3.3+ is also now supported! However, this library has not yet been used as thoroughly with Python 3, so we'd recommend testing before deploying with Python 3 in production.

[2]Listed under Python 3 categories on PyPi

当 GoogleCloud SDK 找不到可执行文件时会发生这种情况 python.exe。它会自行下载 python27,但会安装更新版本的 python(例如 3x),以及相应的 环境变量会继续干扰

因此,最佳做法是:

  • 下载并安装 Python 2.7 在任何需要的位置,比如 C:\Program Files\Python27
  • 现在添加一个名为CLOUDSDK_PYTHON的新环境变量,并将其值设置为python.exe来自上面的安装.

    • 在我的例子中,它将是 "C:\Program Files\Python27\python.exe"
  • 现在重新运行设置。

  • 如果问题仍然存在,请将 python 2.7 添加到您的 PYTHONPATH & Path 环境变量(系统).
  • 添加后,使用 Move Up (Win10) 将它们向上移动到任何其他 python3x variables 之上,或者只是将路径粘贴到任何其他 python 3x 变量之前。

这将确保您的系统始终将 python2.7 优先于任何其他版本。要检查 python2.7 是否正确添加,请输入 cmd

 python -v

这将告诉您当前使用的 python 解释器的版本。