如何从命令行将 gsutil 设置为 运行

How do you set up gsutil to be run from the command line

我在 64 位 Windows 7 和 64 位 Python 2.7 和 gsutil 版本 4.11

我正在尝试设置 gsutil,以便我可以在 windows 命令提示符下使用命令 python gsutilgsutil 运行 它。我指的是文档 here 中名为 "Facilitating the use of gsutil"

的部分

根据该文档和该指南中的其他参考资料,我应该能够通过使用 python gsutilgsutil 将 gsutil 设置为 运行。我可以通过 cd-ing 到 C:\gsutil 目录或通过 运行ning python C:\gsutil\gsutil 来 运行 gsutil,这可以正常工作,但我想按照指南所说的方式进行设置。我查看了 this 答案,但它只是解释了我已经可以做的事情。

指南的第一步是将 .py 文件与 Python 相关联,我假设这已经完成,因为当我双击 .py 文件时,它 运行s 在 Python,但也许我很困惑。

指南的第二步是将 'gsutil' 文件重命名为 'gsutil.py',但这没有意义,因为 C:\gsutil 文件夹中已经有一个名为 gsutil.py。我已经在 Sublime Text 中打开了这两个文件,它们是不同的,所以也许它们做同样的事情,但我不确定...

第三步是将 C:\gsutil 添加到我的 PATH 环境变量中,但我仍然无法使用命令 python gsutil 运行 gsutil。

我也尝试了第 4 步和第 5 步,但它们也没有帮助我。没有 gsutil\boto 路径(除非他们的意思是 C:\gsutil\third_party\boto)而且我应该能够在与 boto 无关的情况下进行设置。

我仍然可以使用 gsutil,但我想了解为什么我不能 运行 它像 Google 说的那样。感谢您的帮助。

我正在查看 docs for Windows and they do seem a bit messed up. You don't need to rename anything as long as you have installed Python correctly, as you can just invoke 'gsutil.py' from anywhere as long as 'C:\gsutil' (or wherever you installed it) is in your path. The 'gsutil' script is just another Python wrapper that imports 'gsutil.py', which would work on a Unix system to save typing the extension if it was in your path but not on Windows (Windows needs a file extension to associate the type). I'd recommend just installing the Google Cloud SDK using the Windows installer,因为它正确安装了 gsutil 以及 Windows 的 'gsutil.cmd' 包装器,它实际上可以正确地做到这一点。

您只能从安装目录中 运行 'python gsutil',因为 Windows 路径规则永远不会应用于作为另一个命令的参数给出的文件名。

如果你只是想要输入 'gsutil' 的功能,因为它应该工作,'gsutil.cmd' 脚本基本上是这样做的(替换为你安装东西的实际目录):

cmd.exe /C C:\Python27\python.exe "C:\gsutil\gsutil.py" %*"