Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gcloud has stopped working after 7.3.0 update #18529

Closed
5 tasks done
andreikondratev opened this issue Nov 11, 2022 · 14 comments · Fixed by #18559
Closed
5 tasks done

gcloud has stopped working after 7.3.0 update #18529

andreikondratev opened this issue Nov 11, 2022 · 14 comments · Fixed by #18559
Labels
Resolution-External The issue is caused by external component(s).

Comments

@andreikondratev
Copy link

Prerequisites

Steps to reproduce

I installed 7.3.0 with msi and after that kept getting the error like when executing gcloud commands

google-cloud-sdk\platform\bundledpython\python.exe: can't find '__main__' module in ''

Tried to reinstall gcloud (with and without bundled python) and powershell a few times without much luck.

Works fine after downgrade to PS 7.2.5

Expected behavior

PS C:\> gcloud -h
Usage: gcloud [optional flags] <group | command>
  group may be           access-approval | access-context-manager |
                         active-directory | ai | ai-platform | anthos |
                         api-gateway | apigee | app | artifacts | asset |
                         assured | auth | batch | beta | bigtable | billing |
                         bms | builds | certificate-manager | cloud-shell |
                         components | composer | compute | config | container |
                         data-catalog | database-migration | dataflow |
                         dataplex | dataproc | datastore | datastream | debug |
                         deploy | deployment-manager | dns | domains |
                         edge-cloud | emulators | endpoints |
                         essential-contacts | eventarc | filestore | firebase |
                         firestore | functions | game | healthcare | iam | iap |
                         identity | ids | iot | kms | logging | memcache |
                         metastore | ml | ml-engine | monitoring |
                         network-connectivity | network-management |
                         network-security | network-services | notebooks |
                         org-policies | organizations | policy-intelligence |
                         policy-troubleshoot | privateca | projects | pubsub |
                         recaptcha | recommender | redis | resource-manager |
                         resource-settings | run | scc | scheduler | secrets |
                         service-directory | services | source | spanner | sql |
                         storage | tasks | topic | transcoder | transfer |
                         workflows | workspace-add-ons
  command may be         cheat-sheet | docker | feedback | help | info | init |
                         survey | version

For detailed information on this command and its flags, run:
  gcloud --help

Actual behavior

PS C:\> gcloud -h
google-cloud-sdk\platform\bundledpython\python.exe: can't find '__main__' module in ''

Error details

No response

Environment data

Name                           Value
----                           -----
PSVersion                      7.3.0
PSEdition                      Core
GitCommitId                    7.3.0
OS                             Microsoft Windows 10.0.22621
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Visuals

No response

@andreikondratev andreikondratev added the Needs-Triage The issue is new and needs to be triaged by a work group. label Nov 11, 2022
@arifinsiam
Copy link

facing the same issue, have you found any solutions yet?

@cesarjosue-reyes
Copy link

Same issue

@al-cheb
Copy link
Contributor

al-cheb commented Nov 11, 2022

facing the same issue, have you found any solutions yet?

There is no any issue with PowerShell Desktop.

@al-cheb
Copy link
Contributor

al-cheb commented Nov 12, 2022

#13428 (comment)
Workaround is to set $PSNativeCommandArgumentPassing = "Legacy" - https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_Preference_Variables?view=powershell-7.3#psnativecommandargumentpassing

Variables that customize the behavior of PowerShell.

@andykcfung
Copy link

Another workaround is to start "cmd" inside powershell, login and then exit the "cmd" shell.

@andykcfung
Copy link

facing the same issue, have you found any solutions yet?

There is no any issue with PowerShell Desktop.

FWIW, "PowerShell Desktop" is a very old version of PowerShell. Run the command "$PSVersionTable" on mine and it shows "PSVersion" to be 5.1.x

@SteveL-MSFT
Copy link
Member

If someone can confirm that setting $PSNativeCommandArgumentPassing = "Legacy" works and gcloud works, we can add that to legacy list so that it defaults to previous behavior. Also, is the actual command gcloud.exe or gcloud.cmd? The latter should automatically use legacy passing.

@SehiiRohoza
Copy link

SehiiRohoza commented Nov 14, 2022

If someone can confirm that setting $PSNativeCommandArgumentPassing = "Legacy" works and gcloud works, we can add that to legacy list so that it defaults to previous behavior. Also, is the actual command gcloud.exe or gcloud.cmd? The latter should automatically use legacy passing.

Works for me.

@ghost ghost added the In-PR Indicates that a PR is out for the issue label Nov 14, 2022
@SteveL-MSFT SteveL-MSFT self-assigned this Nov 14, 2022
@ghost ghost added Resolution-Fixed The issue is fixed. and removed In-PR Indicates that a PR is out for the issue Needs-Triage The issue is new and needs to be triaged by a work group. labels Nov 15, 2022
@daxian-dbw
Copy link
Member

daxian-dbw commented Nov 16, 2022

Re-open this issue.

Running gcloud is not running gcloud.exe, but resolved to the gcloud.ps1 file under the installation folder. The gcloud.ps1 file eventually calls python.exe with a generated argument array. For the gcloud -h, the generated argument array is essentially the following array:

$arg_array = $('', '-S', 'C:\Users\username\AppData\Local\Google\Cloud SDK\google-cloud-sdk\lib\gcloud.py', '-h')

The leading empty string is the problem that cause it fail in the new Standard/Windows mode. With legacy mode, the leading empty string is ignored when passing to python.exe, but with the new standard/windows mode, the empty string is passed in as well, which causes python.exe to fail.

gcloud will be removed from the list by #18575.
For now, setting $PSNativeCommandArgumentPassing = "Legacy" is the workaround to use gcloud in PS 7.3.0

@daxian-dbw daxian-dbw reopened this Nov 16, 2022
@SteveL-MSFT SteveL-MSFT added Resolution-External The issue is caused by external component(s). and removed Resolution-Fixed The issue is fixed. labels Nov 16, 2022
@SteveL-MSFT SteveL-MSFT removed their assignment Nov 16, 2022
@SteveL-MSFT
Copy link
Member

SteveL-MSFT commented Nov 16, 2022

Created https://issuetracker.google.com/issues/259295558

@ghost
Copy link

ghost commented Nov 17, 2022

This issue has been marked as external and has not had any activity for 1 day. It has been be closed for housekeeping purposes.

@ghost ghost closed this as completed Nov 17, 2022
@veleek
Copy link

veleek commented Nov 30, 2022

For anybody who runs into this issue and is looking for a quick workaround. Open up gcloud.ps1 (you can get the path using Get-Command gcloud | Select-Object Source) and then replace Line 109:

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

with

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

@catosaurusrex2003
Copy link

may not be related to the real problem of this error but i was getting the exact same error and
my error got SOLVED
the problem was that while installing gcloud CLI i installed it just for my user on C drive , whereas i was calling gcloud outside of the user path.
then i opened powershell inside user and then gcloud started to work

@alteredego
Copy link

alteredego commented Jan 18, 2023

I can confirm that this has now been fixed with Google Cloud CLI version 413.0.0
https://issuetracker.google.com/issues/259295558

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Resolution-External The issue is caused by external component(s).
Projects
None yet
Development

Successfully merging a pull request may close this issue.