Davidjb
Davidjb

Reputation: 1240

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

I'm on 64-bit Windows 7 with 64-bit Python 2.7 and gsutil version 4.11

I'm trying to set up gsutil so that I can run it from the windows command prompt with the commands python gsutil or gsutil. I'm referring to the documentation here in the section called "Facilitating the use of gsutil"

According to that documentation and other references in that guide, I should be able to set up gsutil to run by using either python gsutil or just gsutil. I am able to run gsutil by cd-ing to the C:\gsutil directory or by running python C:\gsutil\gsutil, which will work fine, but I'd like to set it up the way the guide says it can be set up. I've looked at this answer but it just explains what I already can do.

The first step of the guide is associate .py files with Python, which I'm assuming is already done because when I double click a .py file, it runs in Python, but maybe I'm confused.

The second step of the guide is to rename the 'gsutil' file to 'gsutil.py', but that doesn't make sense because there's already a file in the C:\gsutil folder called gsutil.py. I've opened both the files in Sublime Text and they're both different, so maybe they do the same thing but I'm not sure...

The third step is to add C:\gsutil to my PATH environment variable, but I'm still unable to run gsutil using the command python gsutil after doing that.

I've also tried steps 4 and 5 but they don't help me either. There is no gsutil\boto path (unless they mean C:\gsutil\third_party\boto) and I should be able get this set up without anything to do with boto anyways.

I can still use gsutil but I'd like to understand why I can't run it the way Google says I should be able to. Thanks for any help.

Upvotes: 1

Views: 3508

Answers (1)

Adam
Adam

Reputation: 5985

I'm looking at the 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 as it installs gsutil properly along with a 'gsutil.cmd' wrapper for Windows which actually does this properly.

You could only ever run 'python gsutil' from inside the installation directory as Windows path rules would never apply to a filename given as an argument to another command.

If you just want the functionality of typing 'gsutil' as it is supposed to work, the 'gsutil.cmd' script essentially does this (substituting with the actual directories where you installed stuff):

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

Upvotes: 1

Related Questions