Score:3

Unable to run the Google Cloud SDK CLI on Windows + Powershell 7 due to python issues

cn flag

Recently after having no problems for months I suddenly am unable to run the Google Cloud SDK CLI / gcloud commands in Windows Terminal / PowerShell 7 (7.3).

The error I am getting is:

>gcloud
C:\Users\admin10lap\AppData\Local\Programs\Python\Python39\python.exe: can't find '__main__' module in ''

This appears to happen both with and without the bundled python option on the Google Cloud SDK installer (as I've tried re-installing the Google Cloud SDK multiple times).

Strangely, I do not get this error when using PowerShell 5.x or CMD prompt and nthe gcp SDK CLI runs fine in those instances.

PowerShell 7 has become my daily driver due to the enhancements and customizations it offers when used in conjunction with Windows terminal, so I'm desperate to get it working again.

I'm a bit out of my depth on how to troubleshoot this specific issue, if anyone has any insight as to what might be at play causing PowerShell 7 to throw this python error I would greatly appreciate any feedback.

Thanks.

Score:3
cn flag

Upon checking around, I found this Github issue link wherein a bug was already filed after gcloud stopped working after updating PowerShell to 7.3. An issue is filed for Google Cloud as well. You can keep track of both links for now.

As of the moment, there are some workarounds that we could perform:

Let me know if you have questions or clarifications.

cn flag
Thanks Robert, you're a lifesaver! I will give the Preference Variable option a shot and otherwise go for 7.2. Much appreciated!
Score:3
mx flag

Since the first answer was accepted there have been several updates to the tickets at Google Cloud and Github. The issue was fixed per the former in gcloud SDK version 413.0.0. If you are running a version older than that, you can perform the fix manually. First, use this command to get the location of gcloud.ps1:

Get-Command gcloud | Select-Object Source

Next, edit that file. Around or at line 109 will be this text:

$run_args_array += $cloudsdk_python_args.split(' ')

replace the line entirely with this:

$run_args_array += $cloudsdk_python_args.split(' ', [StringSplitOptions]::RemoveEmptyEntries)

This is the fix from version 413.0.0, so gcloud will run after that. I recommend that the very first invocation after this point be gcloud components update.

(h/t to this comment on GitHub for the above steps)

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.